Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Write a JUnit test using any of the usual JUnit 4.x annotations and use @Inject in combination with appropriate qualifiers to inject the beans under test.

Example:

Code Block

@RunWith( PaxExam.class )
public class VanillaTest
{
    @Inject
    @Vanilla
    private IceCreamService vanilla;

    @Inject
    @Chocolate
    private IceCreamService chocolate;

    @Inject
    private IceCreamService defaultFlavour;

    @Test
    public void checkVanillaFlavour()
    {
        assertThat( vanilla.getFlavour(), is( "Vanilla" ) );
    }

    @Test
    public void checkChocolateFlavour()
    {
        assertThat( chocolate.getFlavour(), is( "Chocolate" ) );
    }

    @Test
    public void checkDefaultFlavour()
    {
        assertThat( defaultFlavour.getFlavour(), is( "Vanilla" ) );
    }
}

...

  • Make sure that all dependencies of your system under test and all required Pax Exam modules are on the classpath (see Pax Exam Maven Dependencies).
  • Create a configuration file exam.properties in the root of your classpath with the following contents:

    No Format
    
    pax.exam.system = cdi
    
  • Run your test or a whole set of tests just like any plain old JUnit test, e.g. from your IDE, under Maven Surefire or as part of your Continuous Integration job.

...