Skip to content

Commit 6200290

Browse files
committed
Update README to document the new TestClassWatcher2 interface
1 parent 7c53508 commit 6200290

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,28 @@ import com.nordstrom.automation.junit.AtomicTest;
4343
import com.nordstrom.automation.junit.LifecycleHooks;
4444
import com.nordstrom.automation.junit.MethodWatcher;
4545
import com.nordstrom.automation.junit.RunReflectiveCall;
46-
import com.nordstrom.automation.junit.TestClassWatcher;
46+
import com.nordstrom.automation.junit.TestClassWatcher2;
4747
import org.junit.runners.model.FrameworkMethod;
4848
import org.junit.runners.model.TestClass;
4949

50-
public class ExploringWatcher implements TestClassWatcher, MethodWatcher {
50+
public class ExploringWatcher implements TestClassWatcher2, MethodWatcher {
5151

5252
...
5353

5454
@Override
55-
public void testClassStarted(TestClass testClass) {
56-
// get the 'atomic test' for this runner
57-
AtomicTest atomicTest = RunReflectiveCall.getAtomicTestFor(testClass);
58-
// get the 'particle' methods of this 'atomic test'
59-
List<FrameworkMethod> particles = atomicTest.getParticles();
60-
// get the parent of this runner
61-
TestClass parent = LifecycleHooks.getParentOf(testClass);
55+
public void testClassStarted(TestClass testClass, Object runner) {
56+
// if this is a Suite runner
57+
if (runner instanceof org.junit.runners.Suite) {
58+
// get the parent of this runner
59+
Object parent = LifecycleHooks.getParentOf(runner);
60+
...
61+
} else {
62+
// get the 'atomic test' for this runner
63+
AtomicTest atomicTest = RunReflectiveCall.getAtomicTestFor(testClass);
64+
// get the 'particle' methods of this 'atomic test'
65+
List<FrameworkMethod> particles = atomicTest.getParticles();
66+
...
67+
}
6268
...
6369
}
6470

@@ -242,11 +248,12 @@ The preceding **ServiceLoader** provider configuration files declare a **JUnit F
242248
**RunnerWatcher** provides callbacks for events in the lifecycle of **`ParentRunner`** objects. It receives the following notifications:
243249
* A **`ParentRunner`** object is about to run.
244250
* A **`ParentRunner`** object has finished running.
245-
* [TestClassWatcher](https://github.com/Nordstrom/JUnit-Foundation/blob/master/src/main/java/com/nordstrom/automation/junit/TestClassWatcher.java)
246-
**TestClassWatcher** provides callbacks for events in the lifecycle of **`TestClass`** objects. It receives the following notifications:
247-
* A **`TestClass`** object has been created to represent a JUnit test class or suite. Each **`TestClass`** has a one-to-one relationship with the JUnit runner that created it.
251+
* [TestClassWatcher2](https://github.com/Nordstrom/JUnit-Foundation/blob/master/src/main/java/com/nordstrom/automation/junit/TestClassWatcher2.java)
252+
**TestClassWatcher2** provides callbacks for events in the lifecycle of **`TestClass`** objects. It receives the following notifications:
253+
* A **`TestClass`** object has been created to represent a JUnit test class or suite. Each **`TestClass`** has a one-to-one relationship with the JUnit runner that created it. (see **NOTE**)
248254
* A **`TestClass`** object has been scheduled to run. This signals that the first child of the JUnit test class or suite is about start.
249255
* A **`TestClass`** object has finished running. This signals that the last child of the JUnit test class or suite is done.
256+
* **NOTE** - This interface supercedes a prior version, adding the runner object to start/finish notifications. Test executers like Maven Surefire create suite runners for their own purposes (e.g. - parallel execution context). This breaks the one-to-one relationship between **`TestClass`** objects and runners. Consequently, the **`TestClass`** object cannot be assumed to represent a unique context.
250257
* [TestObjectWatcher](https://github.com/Nordstrom/JUnit-Foundation/blob/master/src/main/java/com/nordstrom/automation/junit/TestObjectWatcher.java)
251258
**TestObjectWatcher** provides callbacks for events in the lifecycle of Java test class instances. It receives the following notification:
252259
* An instance of a JUnit test class has been created for the execution of a single `atomic test`.

0 commit comments

Comments
 (0)