HHH-6677 skip @BeforeClassOnce / @AfterClassOnce if test is ignored
This commit is contained in:
parent
3fe833456b
commit
bd54fe08f5
|
@ -71,8 +71,32 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
return testClassMetadata;
|
||||
}
|
||||
|
||||
private Boolean isAllTestsIgnored = null;
|
||||
|
||||
private boolean isAllTestsIgnored() {
|
||||
if ( isAllTestsIgnored == null ) {
|
||||
if ( computeTestMethods().isEmpty() ) {
|
||||
isAllTestsIgnored = true;
|
||||
}
|
||||
else {
|
||||
isAllTestsIgnored = true;
|
||||
for ( FrameworkMethod method : computeTestMethods() ) {
|
||||
Ignore ignore = method.getAnnotation( Ignore.class );
|
||||
if ( ignore == null ) {
|
||||
isAllTestsIgnored = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return isAllTestsIgnored;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBeforeClasses(Statement statement) {
|
||||
if ( isAllTestsIgnored() ) {
|
||||
return super.withBeforeClasses( statement );
|
||||
}
|
||||
return new BeforeClassCallbackHandler(
|
||||
this,
|
||||
super.withBeforeClasses( statement )
|
||||
|
@ -81,6 +105,9 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
|
||||
@Override
|
||||
protected Statement withAfterClasses(Statement statement) {
|
||||
if ( isAllTestsIgnored() ) {
|
||||
return super.withAfterClasses( statement );
|
||||
}
|
||||
return new AfterClassCallbackHandler(
|
||||
this,
|
||||
super.withAfterClasses( statement )
|
||||
|
|
Loading…
Reference in New Issue