Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-2032] Fix test count when using @Disabled at class level #564

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,25 @@ private String safeGetMessage( Throwable throwable )
@Override
public void executionSkipped( TestIdentifier testIdentifier, String reason )
{
testStartTime.remove( testIdentifier );
runListener.testSkipped( createReportEntry( testIdentifier, null, emptyMap(), reason, null ) );
boolean isClass = testIdentifier.isContainer()
&& testIdentifier.getSource().filter( ClassSource.class::isInstance ).isPresent();
boolean isTest = testIdentifier.isTest();

if ( isClass )
{
SimpleReportEntry report = createReportEntry( testIdentifier );
runListener.testSetStarting( report );
for ( TestIdentifier child : testPlan.getChildren( testIdentifier ) )
{
runListener.testSkipped( createReportEntry( child, null, emptyMap(), reason, null ) );
}
runListener.testSetCompleted( report );
}
else if ( isTest )
{
testStartTime.remove( testIdentifier );
runListener.testSkipped( createReportEntry( testIdentifier, null, emptyMap(), reason, null ) );
}
}

private SimpleReportEntry createReportEntry( TestIdentifier testIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import org.apache.maven.surefire.api.report.TestOutputReportEntry;
import org.apache.maven.surefire.api.report.TestReportListener;
import org.apache.maven.surefire.api.report.TestSetReportEntry;
import org.apache.maven.surefire.report.PojoStackTraceWriter;
import org.apache.maven.surefire.api.report.ReportEntry;
import org.apache.maven.surefire.api.report.SimpleReportEntry;
Expand Down Expand Up @@ -394,28 +395,39 @@ public void notifiedWhenMethodExecutionSkipped()
}

@Test
public void notifiedWithCorrectNamesWhenClassExecutionSkipped()
{
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass( ReportEntry.class );
TestPlan testPlan = TestPlan.from( singletonList( new EngineDescriptor( newId(), "Luke's Plan" ) ) );
public void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception
{
EngineDescriptor engineDescriptor = new EngineDescriptor( newId(), "Luke's Plan" );
TestDescriptor classTestDescriptor = newClassDescriptor();
TestDescriptor method1 = newMethodDescriptor();
classTestDescriptor.addChild( method1 );
TestDescriptor method2 = newMethodDescriptor();
classTestDescriptor.addChild( method2 );
engineDescriptor.addChild( classTestDescriptor );
TestPlan testPlan = TestPlan.from( singletonList( engineDescriptor ) );
adapter.testPlanExecutionStarted( testPlan );

TestIdentifier classIdentifier =
identifiersAsParentOnTestPlan( testPlan, newEngineDescriptor(), newClassDescriptor() );

adapter.executionSkipped( classIdentifier, "test" );
verify( listener ).testSkipped( entryCaptor.capture() );

ReportEntry entry = entryCaptor.getValue();
assertNull( entry.getName() );
assertEquals( MyTestClass.class.getTypeName(), entry.getSourceName() );
}
ArgumentCaptor<TestSetReportEntry> entryCaptor1 = ArgumentCaptor.forClass( TestSetReportEntry.class );
ArgumentCaptor<ReportEntry> entryCaptor2 = ArgumentCaptor.forClass( ReportEntry.class );
ArgumentCaptor<ReportEntry> entryCaptor3 = ArgumentCaptor.forClass( ReportEntry.class );
ArgumentCaptor<TestSetReportEntry> entryCaptor4 = ArgumentCaptor.forClass( TestSetReportEntry.class );

@Test
public void notifiedWhenEngineExecutionSkipped()
{
adapter.executionSkipped( newEngineIdentifier(), "test" );
verify( listener ).testSkipped( any() );
adapter.executionSkipped( classIdentifier, "test" );
verify( listener ).testSetStarting( entryCaptor1.capture() );
verify( listener ).testSkipped( entryCaptor2.capture() );
verify( listener ).testSkipped( entryCaptor3.capture() );
verify( listener ).testSetCompleted( entryCaptor4.capture() );

ReportEntry entry1 = entryCaptor1.getValue();
assertNull( entry1.getName() );
assertEquals( MyTestClass.class.getTypeName(), entry1.getSourceName() );

ReportEntry entry4 = entryCaptor1.getValue();
assertNull( entry4.getName() );
assertEquals( MyTestClass.class.getTypeName(), entry4.getSourceName() );
}

@Test
Expand Down