0

Edited to simplify the example...

I'm migrating the system to Maven. I want to use PaxExam to run the test with TestNg.

I'm trying to run a simple test using PaxExam:

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MyTest</groupId>
    <artifactId>PaxExam</artifactId>
    <version>0.0.2</version>
    <packaging>jar</packaging>
    <name>Prove PaxExam</name>

    <properties>
        <exam.version>3.3.0</exam.version>
        <url.version>1.6.0</url.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-container-native</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-testng</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-link-mvn</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.url</groupId>
            <artifactId>pax-url-aether</artifactId>
            <version>${url.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.framework</artifactId>
            <version>4.0.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>0.9.29</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.29</version>
            <scope>test</scope>
        </dependency>
            <dependency>
        <groupId>org.ow2.spec.ee</groupId>
        <artifactId>ow2-jta-1.1-spec</artifactId>
        <version>1.0.12</version>
        <scope>test</scope>
    </dependency>   
    </dependencies>
</project>

Java program:

   package MyTest.PaxExam;
    import static org.ops4j.pax.exam.CoreOptions.*;
    import static org.testng.Assert.*;
    import javax.inject.Inject;
    import org.ops4j.pax.exam.Option;
    import org.ops4j.pax.exam.Configuration;
    import org.ops4j.pax.exam.ConfigurationFactory;
    import org.ops4j.pax.exam.spi.reactors.PerClass;
    import org.ops4j.pax.exam.testng.listener.PaxExam;
    import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
    import org.osgi.framework.Bundle;
    import org.osgi.framework.BundleContext;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;
    import ch.qos.logback.classic.*;
    import org.slf4j.LoggerFactory;

    @Listeners(PaxExam.class)
    @ExamReactorStrategy(PerClass.class)
    public class Prove {

        @Inject
        BundleContext bc;

        @Configuration
        public Option[] config() {
            System.out.println("config() called");
            return options(mavenBundle("org.testng","testng","6.3.1"));         
        }


        @org.testng.annotations.Test
        public void checkInject() {
            System.out.println("checkInject() called");
            assertNotNull(bc);
        }   
    }

The results that I have, when I verify the test, are:

    [INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Prove PaxExam 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ PaxExam ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\users\dan\desktop\acf\MyTest2\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ PaxExam ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ PaxExam ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ PaxExam ---
[INFO] Compiling 1 source file to C:\users\dan\desktop\acf\MyTest2\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ PaxExam ---
[INFO] Surefire report directory: C:\users\dan\desktop\acf\MyTest2\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ PaxExam ---
[INFO] Building jar: C:\users\dan\desktop\acf\MyTest2\target\PaxExam-0.0.2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.246s
[INFO] Finished at: Fri Dec 06 16:33:14 CET 2013
[INFO] Final Memory: 15M/226M
[INFO] ------------------------------------------------------------------------

The container is not started, no test is run.

2 Answers2

0

Not sure what you're trying to do. If you're trying to run OSGi tests with an embedded OSGi framework, don't use the exam-maven-plugin.

If you're trying to run plain old unit/integration tests communicating with an external OSGi application, you can use the exam-maven-plugin to launch that application in Pax Exam server mode, but then there's no need to use Pax Exam in your tests.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
  • I am trying to run a simple integrated osgi test. In this example, there is no bundle under test, just the test that should be run by pax exam. The first attempt was done without the inclusion of the plugins (exam-maven-plugin, maven-failsafe-plugin) as the available documentation for pax exam say that is for server mode. When maven is run, there is no pax exam container started at all. If I add the plugins, then at least we see the container started, the configuration method is called, but not the method annotated as @Test. – Cristina Galán Dec 06 '13 at 08:58
  • Take a look at Pax Exam's own [TestNG regression tests](https://github.com/ops4j/org.ops4j.pax.exam2/tree/master/itest/osgi/src/it/regression-testng) and start from there. – Harald Wellmann Dec 06 '13 at 14:16
  • I don't see anything there that differs from the example I've provided. What seems to be happening is that pax exam is not seeing that i've defined a dependency to the felix framework, and does not start felix in the test container. Why, is the question. – Cristina Galán Dec 06 '13 at 14:33
  • hwellmann, I have simplified the above example to what I understand from the available documentation on how it should work. Does the above example work for you ? It really seems that pax is not picking up the felix dependency. Thanks. – Cristina Galán Dec 06 '13 at 15:37
  • I can't reproduce your problem. Your Maven output does not seem to match the POM and test source you posted. Try to match your Logback version to the SLF4J api version and make sure to avoid any `org.osgi.core` transitive dependency by excluding it or by putting Felix on the top of your dependency list. – Harald Wellmann Dec 07 '13 at 12:36
0

Finally!

According to the surefire plugin documention : http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

As long as they are named using the defaults such as *Test.java they will be run by Surefire as TestNG tests.

If you'd like to use a different naming scheme, you can change the includes parameter, as discussed in the Inclusions and Exclusions of Tests example.

My test class name did not start with Test nor end with Test. Changing the class name to TestProve.java solves the problem.

Thanks to hwellmann for his time.