File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
main/java/com/nordstrom/automation/junit
test/java/com/nordstrom/automation/junit Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,9 @@ static <T> AtomicTest<T> getAtomicTestOf(Object testKey) {
145145 */
146146 private static <T > AtomicTest <T > setTestFailure (Failure failure ) {
147147 AtomicTest <T > atomicTest = getAtomicTestOf (Run .getThreadRunner ());
148+ if (atomicTest == null ) {
149+ atomicTest = getAtomicTestOf (failure .getDescription ());
150+ }
148151 atomicTest .setThrowable (failure .getException ());
149152 return atomicTest ;
150153 }
Original file line number Diff line number Diff line change 1+ package com .nordstrom .automation .junit ;
2+
3+ import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertFalse ;
5+
6+ import org .junit .runner .JUnitCore ;
7+ import org .junit .runner .Result ;
8+ import org .junit .runner .notification .Failure ;
9+ import org .testng .annotations .Test ;
10+
11+ public class BeforeClassFailureTest {
12+
13+ @ Test
14+ public void verifyBeforeClassExceptionHandling () {
15+ JUnitCore runner = new JUnitCore ();
16+ Result result = runner .run (BeforeClassThrowsException .class );
17+ assertFalse (result .wasSuccessful ());
18+ assertEquals (1 , result .getFailureCount ());
19+ Failure failure = result .getFailures ().get (0 );
20+ assertEquals (RuntimeException .class , failure .getException ().getClass ());
21+ assertEquals ("Must be failed" , failure .getMessage ());
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package com .nordstrom .automation .junit ;
2+
3+ import static org .junit .Assert .assertTrue ;
4+
5+ import org .junit .BeforeClass ;
6+ import org .junit .Test ;
7+
8+ public class BeforeClassThrowsException extends TestBase {
9+
10+ @ BeforeClass
11+ public static void failing () {
12+ throw new RuntimeException ("Must be failed" );
13+ }
14+
15+ @ Test
16+ public void happy () {
17+ assertTrue (true );
18+ }
19+
20+ @ Test
21+ public void sad () {
22+ assertTrue (false );
23+ }
24+
25+ }
You can’t perform that action at this time.
0 commit comments