java class 中的多个 @Test 方法因 java.lang.Exception 失败:没有可运行的方法

Multiple @Test method in a java class fails with java.lang.Exception: No runnable methods

我在 class 中有多个 @Test 方法,而 运行 宁 paxexam 它失败并出现以下异常

java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:169)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:104)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:355)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
    at org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.<init>(ContainerTestRunner.java:54)
    at org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunnerBuilder.runnerForClass(ContainerTestRunnerBuilder.java:48)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunnerClassRequest.getRunner(ContainerTestRunnerClassRequest.java:61)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:31)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:138)

以下是pax考试代码。当我 运行 这段代码时,我得到一个异常。如果我将此注释 @ExamReactorStrategy(PerClass.class) 更改为 @ExamReactorStrategy(PerMethod.class) 再添加一点,这将起作用问题是测试容器在每个方法后重新启动

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class Integration5TestCases {

    private static Logger LOG = LoggerFactory.getLogger(IntegrationTestCases.class);

    @Inject
    private BundleContext bc;


    @Inject
    protected FeaturesService featuresService;

    /**
     * To make sure the tests run only when the boot features are fully
     * installed
     */
    @Inject
    BootFinished bootFinished;



@Configuration
    public static Option[] configuration() throws Exception {
        MavenUrlReference oracleLib = maven()
                .groupId("com.oracle")
                .artifactId("ojdbc6")
                .version("11.2.0")
                .type("jar");

        MavenUrlReference dbHandler = maven().groupId("Oracle")
                .artifactId("DBHandler")
                .versionAsInProject()
                .type("xml")
                .classifier("features");

        return new Option[] {
                returnNewKarafInstance(),
                systemProperty(PaxExamConstants.ORCALESYSPROPNAME).value(dbHandler.getURL()),
                KarafDistributionOption.debugConfiguration("8898", true),
                bootClasspathLibrary(oracleLib),
                configureConsole().ignoreLocalConsole(),
                logLevel(LogLevel.INFO),
                keepRuntimeFolder(),

        };
    }

    private static KarafDistributionBaseConfigurationOption returnNewKarafInstance(){
        return karafDistributionConfiguration().frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf")
                .type("zip").versionAsInProject())
                .unpackDirectory(new File("target/paxexam/unpack/"))
                .useDeployFolder(false);
    }


    @Inject 
    SessionFactory commandProcessor;



    @Test
    public void test1() throws Exception {
    System.out.println("sd");

    }

@Test
    public void test2() throws Exception {
    System.out.println("sd");

    }
}

发生这种情况是因为 junit 库在 karaf 容器中被初始化了两次。感谢大家的帮助。