eclipse 无法使字段成为私有的最终java.util.比较器java.util.TreeMap.比较器可访问:java.base不会对未命名的模块“打开java.util”

jjhzyzn0  于 2022-11-04  发布在  Eclipse
关注(0)|答案(5)|浏览(191)

我已经创建了一个Cucumber特性文件和步骤文件,然后我点击了特性文件的“运行配置”,我在控制台中看到了以下内容。我该如何解决这个问题?


* Feature: Login into account

  Existing user should be able to login to account using correct credentials

Scenario: Login into account with correct credentials     # C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4

Given User navigates to stackoverflow website           # LoginSteps.user_navigates_to_stackoverflow_website()
      java.lang.ExceptionInInitializerError
        at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
        at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
        at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
        at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
        at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
        at cucumber.runtime.Runtime.runStep(Runtime.java:300)
        at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
        at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
        at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
        at cucumber.runtime.Runtime.run(Runtime.java:122)
        at cucumber.api.cli.Main.run(Main.java:36)
        at cucumber.api.cli.Main.main(Main.java:18)
        at ✽.Given User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:5)

 Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @5afa04c
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
        at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
        at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
        at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
        at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
        at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
        at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
        at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
        at cucumber.runtime.Runtime.runStep(Runtime.java:300)
        at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
        at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
        at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
        at cucumber.runtime.Runtime.run(Runtime.java:122)
        at cucumber.api.cli.Main.run(Main.java:36)
        at cucumber.api.cli.Main.main(Main.java:18)

And User clicks on the login button on homepage         # LoginSteps.user_clicks_on_the_login_button_on_homepage()

And User enters a valid username                        # LoginSteps.user_enters_a_valid_username()

And User enters a valid password                        # LoginSteps.user_enters_a_valid_password()

When User clicks on the login button                    # LoginSteps.user_clicks_on_the_login_button()

Then User should be taken to the successfull login page # LoginSteps.user_should_be_taken_to_the_successfull_login_page()

Failed scenarios:
C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4 # Scenario: Login into account with correct credentials
1 Scenarios (1 failed)
6 Steps (1 failed, 5 skipped)
0m0,357s

java.lang.ExceptionInInitializerError
    at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
    at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
    at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
    at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:122)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
    at ✽.Given User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:5)

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @5afa04c
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
    at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
    at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
    at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
    at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
    at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
    at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:122)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)*
3z6pesqy

3z6pesqy1#

我没有安装 cucumber 功能,所以在我的设置问题是不相关的。什么帮助我是更新我的pom文件中的maven插件设置如下。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</plugin>
zmeyuzjn

zmeyuzjn2#

您的Cucumber版本与Java版本不兼容。请升级Cucumber或降级Java。
由于您正在测试的场景,我猜您正在使用旧的教程。以下是最新的教程:
https://cucumber.io/docs/guides/10-minute-tutorial/

8fsztsew

8fsztsew3#

更改maven依赖项。我的应用程序在pom.xml中使用info-cukes表示cucumber。我用io-cucumber更改了它们。它对我很有效。

qxgroojn

qxgroojn4#

我也遇到过同样的问题。
但是用Asaf Magen发布的解决方案解决了这个问题。
请记住更新Maven项目:
右键单击项目-〉Maven -〉更新项目
非常感谢Asaf!!

ecr0jaav

ecr0jaav5#

我遇到过同样的问题,但使用以下代码解决了该问题。

功能文件*****

Feature: Application login
Scenario: Login into Application
Given user click on login page
When user enter username password
Then user can see home page

步骤定义文件*

package StepDefinations;
import org.junit.runner.RunWith;
@RunWith(io.cucumber.junit.Cucumber.class)
public class StepDefination {
@io.cucumber.java.en.Given("^user click on login page$")
public void user_click_on_login_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 1");
}

@io.cucumber.java.en.When("^user enter username password$")
public void user_enter_username_password() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 2");
}

@io.cucumber.java.en.Then("^user can see home page$")
public void user_can_see_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 3");
}}

测试运行器文件****

package cucumber.Options;
import org.junit.runner.RunWith;
@RunWith(io.cucumber.junit.Cucumber.class)
@io.cucumber.junit.CucumberOptions(features="src/test/java/features",` `glue={"StepDefinations"})

public class TestRunner {}

相关问题