-2

I have multiple @Test method in a class while running the paxexam it fails with the below Exception

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)

The below is the pax exam code. When i run this code i get an exception. Adding one more point if i change this annotation @ExamReactorStrategy(PerClass.class) to @ExamReactorStrategy(PerMethod.class) this will work the problem is test container restarts after every method

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

    }
}
Charity
  • 213
  • 1
  • 5
  • 23
  • 1
    Could you please show us the code. – Stefan Birkner Feb 14 '16 at 20:22
  • Are you importing `org.junit.Test` or something else like `org.testng.annotations.Test`? – Brett Kail Feb 15 '16 at 00:02
  • I have added the code in the question please take a look – Charity Feb 15 '16 at 03:27
  • I am importing org.junit.Test – Charity Feb 15 '16 at 04:56
  • 1
    Probably the org.junit package is available in two different bundles. Your test class uses one of them, while Pax Exam uses the other. To try if this is the case, either check the wirings via the console or webconsole; or debug and see if the classloader of Test class is the same in your code as in BlockJUnit4ClassRunner – Balazs Zsoldos Feb 15 '16 at 15:49
  • if you can, try to upload in github a small project showing this behavior. there is probably a "small details" which make this test fail. The code posted here look good to me – Jérémie B Feb 15 '16 at 18:51

1 Answers1

0

This was happening because junit lib was initialized twice inside the karaf container. Thanks for the help guys.

Charity
  • 213
  • 1
  • 5
  • 23