2020import io .qameta .allure .Step ;
2121import io .qameta .allure .aspects .AttachmentsAspects ;
2222import io .qameta .allure .aspects .StepsAspects ;
23- import io .qameta .allure .junitplatform .AllurePostDiscoveryFilter ;
2423import io .qameta .allure .model .ExecutableItem ;
2524import io .qameta .allure .model .FixtureResult ;
2625import io .qameta .allure .model .Label ;
4645import io .qameta .allure .spock2 .samples .TestWithAnnotationsOnClass ;
4746import io .qameta .allure .spock2 .samples .TestWithCustomAnnotations ;
4847import io .qameta .allure .spock2 .samples .TestWithSteps ;
48+ import io .qameta .allure .spock2 .samples .TestsWithIdForFilter ;
49+ import io .qameta .allure .test .AllureFeatures ;
4950import io .qameta .allure .test .AllureResults ;
5051import io .qameta .allure .test .AllureResultsWriterStub ;
5152import io .qameta .allure .testfilter .TestPlan ;
53+ import io .qameta .allure .testfilter .TestPlanV1_0 ;
5254import org .apache .commons .lang3 .tuple .Pair ;
5355import org .apache .commons .lang3 .tuple .Triple ;
5456import org .junit .jupiter .api .Test ;
@@ -494,6 +496,107 @@ void shouldNotMixUpFixturesBetweenTests() {
494496 );
495497 }
496498
499+ private final TestPlanV1_0 .TestCase onlyId2 = new TestPlanV1_0 .TestCase ().setId ("2" );
500+ private final TestPlanV1_0 .TestCase onlyId4 = new TestPlanV1_0 .TestCase ().setId ("4" );
501+
502+ private final TestPlanV1_0 .TestCase test1 = new TestPlanV1_0 .TestCase ().setId ("1" )
503+ .setSelector ("io.qameta.allure.spock2.samples.TestsWithIdForFilter.test 1" );
504+ private final TestPlanV1_0 .TestCase test2 = new TestPlanV1_0 .TestCase ()
505+ .setId ("2" )
506+ .setSelector ("io.qameta.allure.spock2.samples.TestsWithIdForFilter.test 2" );
507+ private final TestPlanV1_0 .TestCase test3 = new TestPlanV1_0 .TestCase ()
508+ .setId ("3" )
509+ .setSelector ("io.qameta.allure.spock2.samples.TestsWithIdForFilter.test 3" );
510+
511+ private final TestPlanV1_0 .TestCase correctIdIncorrectSelector = new TestPlanV1_0 .TestCase ()
512+ .setId ("4" )
513+ .setSelector ("io.qameta.allure.spock2.samples.TestsWithIdForFilter_bla.test 3" );
514+ private final TestPlanV1_0 .TestCase correctIdIncorrectSelectorFailed = new TestPlanV1_0 .TestCase ()
515+ .setId ("6" )
516+ .setSelector ("io.qameta.allure.spock2.samples.TestsWithIdForFilter_bla.test 3" );
517+ private final TestPlanV1_0 .TestCase otherId = new TestPlanV1_0 .TestCase ().setId ("4" )
518+ .setSelector ("io.qameta.allure.spock2.samples.TestsWithIdForFilter.test 1" );
519+ private final TestPlanV1_0 .TestCase ignored = new TestPlanV1_0 .TestCase ().setId ("5" )
520+ .setSelector ("io.qameta.allure.testng.samples.TestsWithIdForFilter.test 5" );
521+
522+ @ Test
523+ @ AllureFeatures .Filtration
524+ public void simpleFiltration () {
525+ TestPlanV1_0 plan = new TestPlanV1_0 ().setTests (Arrays .asList (test1 , test2 , test3 ));
526+ List <TestResult > testResults = runClasses (plan , TestsWithIdForFilter .class ).getTestResults ();
527+
528+ assertThat (testResults )
529+ .hasSize (3 )
530+ .extracting (TestResult ::getName , TestResult ::getStatus )
531+ .contains (
532+ tuple ("test 1" , Status .PASSED ),
533+ tuple ("test 2" , Status .PASSED ),
534+ tuple ("test 3" , Status .PASSED )
535+ );
536+ }
537+
538+ @ Test
539+ @ AllureFeatures .Filtration
540+ public void onlyId () {
541+ TestPlanV1_0 plan = new TestPlanV1_0 ().setTests (Arrays .asList (onlyId2 , onlyId4 ));
542+ List <TestResult > testResults = runClasses (plan , TestsWithIdForFilter .class ).getTestResults ();
543+
544+ assertThat (testResults )
545+ .hasSize (2 )
546+ .extracting (TestResult ::getName , TestResult ::getStatus )
547+ .contains (
548+ tuple ("test 4" , Status .PASSED ),
549+ tuple ("test 2" , Status .PASSED )
550+ );
551+ }
552+
553+ @ Test
554+ @ AllureFeatures .Filtration
555+ public void idAssignToOtherTest () {
556+ TestPlanV1_0 plan = new TestPlanV1_0 ().setTests (Collections .singletonList (otherId ));
557+ List <TestResult > testResults = runClasses (plan , TestsWithIdForFilter .class ).getTestResults ();
558+
559+ assertThat (testResults )
560+ .hasSize (2 )
561+ .extracting (TestResult ::getName , TestResult ::getStatus )
562+ .contains (
563+ tuple ("test 1" , Status .PASSED ),
564+ tuple ("test 4" , Status .PASSED )
565+ );
566+ }
567+
568+ @ Test
569+ @ AllureFeatures .Filtration
570+ public void skippedTest () {
571+ TestPlanV1_0 plan = new TestPlanV1_0 ().setTests (Arrays .asList (test1 , ignored ));
572+ List <TestResult > testResults = runClasses (plan , TestsWithIdForFilter .class ).getTestResults ();
573+
574+ assertThat (testResults )
575+ .hasSize (1 )
576+ .extracting (TestResult ::getName , TestResult ::getStatus )
577+ .contains (
578+ tuple ("test 1" , Status .PASSED )
579+ );
580+ }
581+
582+ @ Test
583+ @ AllureFeatures .Filtration
584+ public void correctIdIncorrectSelector () {
585+ TestPlanV1_0 plan = new TestPlanV1_0 ().setTests (
586+ Arrays .asList (test1 , test2 , correctIdIncorrectSelector , correctIdIncorrectSelectorFailed )
587+ );
588+ List <TestResult > testResults = runClasses (plan , TestsWithIdForFilter .class ).getTestResults ();
589+ assertThat (testResults )
590+ .hasSize (4 )
591+ .extracting (TestResult ::getName , TestResult ::getStatus )
592+ .contains (
593+ tuple ("test 1" , Status .PASSED ),
594+ tuple ("test 2" , Status .PASSED ),
595+ tuple ("test 4" , Status .PASSED ),
596+ tuple ("test 6" , Status .FAILED )
597+ );
598+ }
599+
497600 @ Step ("Run classes {classes}" )
498601 public static AllureResults runClasses (final Class <?>... classes ) {
499602 return runClasses (null , classes );
@@ -509,7 +612,6 @@ public static AllureResults runClasses(final TestPlan testPlan, final Class<?>..
509612 .toArray (ClassSelector []::new );
510613
511614 final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder .request ()
512- .filters (new AllurePostDiscoveryFilter (testPlan ))
513615 .selectors (classSelectors )
514616 .build ();
515617
@@ -519,7 +621,7 @@ public static AllureResults runClasses(final TestPlan testPlan, final Class<?>..
519621 .andThenTry (GlobalExtensionRegistry .class ::cast )
520622 .toOptional ()
521623 .orElseThrow (() -> new AssertionError ("could not access globalExtensionRegistry field of RunContext" ));
522- extensionRegistry .getGlobalExtensions ().add (new AllureSpock2 (lifecycle ));
624+ extensionRegistry .getGlobalExtensions ().add (new AllureSpock2 (lifecycle , testPlan ));
523625
524626 final LauncherConfig config = LauncherConfig .builder ()
525627 .enableTestEngineAutoRegistration (false )
0 commit comments