-2

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

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");

    }
}
4

1 回答 1

0

发生这种情况是因为 junit lib 在 karaf 容器内被初始化了两次。谢谢你们的帮助。

于 2016-02-21T18:53:27.617 回答