ops4j / org.ops4j.pax.exam2

Pax Exam is a testing framework for OSGi
https://ops4j1.jira.com/wiki/spaces/PAXEXAM4/
Apache License 2.0
84 stars 100 forks source link

Hooks to Probe creation [PAXEXAM-550] #669

Open ops4j-issues opened 11 years ago

ops4j-issues commented 11 years ago

NiclasH created PAXEXAM-550

At the moment it doesn't seem possible to override how TinyBundles creates the Test Probe.

It would be nice to have a hook into the Probe creation, so that non-conventional probes could be created. We have a case where a user wants to do unittest-like testing with Pax Exam, by letting the Probe be a Fragment that attaches itself to the bundle to be "tested". Quite exotic, but if only the createProbe() could be overridden somehow (without cloning pax-exam-junit), it would be easy...


Votes: 0, Watches: 2

ops4j-issues commented 11 years ago

Harald Wellmann commented

There is a hook for customizing the probe: just use the ProbeBuilder annotation on a method in your test class with the following signature;

@ProbeBuilder
public TestProbeBuilder probe(TestProbeBuilder defaultProbe) {
     // ...
}

You can simply add instructions to the default builder or construct your own builder from scratch and return that in place of the default one.

ops4j-issues commented 11 years ago

NiclasH commented

Quote;
"This by itself won’t work at least not with the native container. One problem is that it tries to start the generated bundle and a BundleFragment throws an exception when trying to start it. Another problem is that the native container is looking for a ProbeInvoker but I don’t see what is it registered by. The pax-exam-invoker-junit activator is registering a ProbeInvokerFactory but it’s not that.

The reason this happens is that ProbeInvoker (more specifically JUnitProbeInvoker) is registered by the bundle watcher when the bundle is started (BundleEvent.STARTED), but as it can’t be started it never happens."