Quick annswer (on mobile): @Inject public BundleContext m_bundleContext; is not support in 2.0.0. There is just parameter injection into the test method (see examples).
Same for @Before/After. Its because Exam2 is pretty much independent of JUnit4 now. We will add support for @Before in the subsequent release, but not in stock 2.0.0. Long explanation possibly on a real computer later. ;) Toni On Thu, Apr 28, 2011 at 1:56 PM, Bram de Kruijff <[email protected]>wrote: > Hi list, > > trying to get up to speed on paxexam 2 I quickly got hello world to > run in the native container. Very fast and elegant! Now I would like > to do some more advanced testing that require more comprehensive > "fixtures". Eg bundles active, services available, configurations > registered etc. I'm not entirely clear in the lifecycle yet and am > wondering what would be the best practice/place of doing so without > poluting every test with boilerplate. Eg. in the outline of my code > below I do not seem to have access to the BundleContext in @Before and > only recieve it in the tests themselves. Any pointers would be much > appreciated! > > thanks, > Bram de Kruijff > > >> sample test code << > > @RunWith(JUnit4TestRunner.class) > @ExamReactorStrategy(AllConfinedStagedReactorFactory.class) > public class InitialTest { > > @Inject > public BundleContext m_bundleContext; > > @Configuration > public Option[] config() { > return options( > junitBundles(), > provision( > myLogService(), > myTestBundle() > )); > } > > > @BeforeClass > public static void setUpOne() throws Exception { > // no bundleContext here > } > > @Before > public void setUp() throws Exception { > // no bundleContext here > } > > @Test > public void testLogServiceAvailable(BundleContext bundleContext) > throws Exception { > assertThat(bundleContext, is(notNullValue())); > ServiceReference logServiceReference = > bundleContext.getServiceReference(LogService.class.getName()); > assertThat(logServiceReference, is(notNullValue())); > try { > Object logServiceObject = > bundleContext.getService(logServiceReference); > assertThat(logServiceObject, is(notNullValue())); > assertThat(logServiceObject, is(instanceOf(LogService.class))); > } > finally { > bundleContext.ungetService(logServiceReference); > } > } > > @Test > public void testMyService1(BundleContext bundleContext) throws Exception > { > // how can be sure that services are registered / configuration set > etc? > } > > @Test > public void testMyService2(BundleContext bundleContext) throws Exception > { > // how can be sure that services are registered / configuration set > etc? > } > } > > _______________________________________________ > general mailing list > [email protected] > http://lists.ops4j.org/mailman/listinfo/general > -- Toni Menzel Source <http://tonimenzel.com>
_______________________________________________ general mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/general
