java - Maven Arquillian Junit 测试失败

标签 java maven junit jboss-arquillian

我正在使用 maven-surefire-plugin 2.20.1 运行 arquillianjunit 4.11:

错误:

[ERROR]   JUnit4Provider.invoke:160->executeTestSet:239->executeWithRerun:275->execute:369 » NoSuchMethod

堆栈跟踪:

java.lang.NoSuchMethodError: org.junit.runners.model.TestClass.getAnnotatedFields()Ljava/util/List;
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:369)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:275)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:239)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:160)

测试类

@RunWith(Arquillian.class)
public class GreeterTest {

    @Deployment
    public static JavaArchive createDeployment() {
        JavaArchive jar = ShrinkWrap
                .create(JavaArchive.class)
                .addClasses(Greeter.class, PhraseBuilder.class)
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
        System.out.println(jar.toString());
        return jar;
    }

    @Inject Greeter greeter;

    @Test
    public void should_create_greeting() {
        Assert.assertEquals(
                "Hello, Earthling!",
                greeter.createGreeting("Earthling")
        );
        greeter.greet(System.out, "Earthling");
    }
}

Maven BOM 导入

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.arquillian</groupId>
        <artifactId>arquillian-bom</artifactId>
        <version>1.4.0.Final</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
</dependencyManagement>

Maven 依赖项

<dependency>
  <groupId>org.jboss.arquillian.junit</groupId>
  <artifactId>arquillian-junit-container</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.jboss.arquillian.container</groupId>
  <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
  <version>1.0.0.CR9</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.jboss.weld</groupId>
  <artifactId>weld-core</artifactId>
  <version>2.3.5.Final</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.6.4</version>
  <scope>test</scope>
</dependency>

最佳答案

请务必使用junit 4.12:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

关于java - Maven Arquillian Junit 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53551233/

相关文章:

java - <[]> 与 <null> 有什么区别

java - 具有多个测试的参数化 junit 测试

java - 将Arraylist添加到自定义对象不更新android中的值

java - Apache Flink Channel 在完成当前部分记录之前收到一个事件

java - Intellij 将其他类的成员突出显示为错误,但编译良好

java - Spring 工具套件 - ClassNotFoundException : oracle. jdbc.driver.OracleDriver

java - 如何以可读格式打印 double ?

java - 解析 xml 响应并将其显示到黑莓主屏幕

java - 有没有办法只通过国家名称获得时区?

java - 我们可以在 Java 中有条件地模拟对象吗?