Skip to content
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 @@ -56,7 +56,7 @@ public FilterResult apply(final TestDescriptor object) {
if (Objects.isNull(testPlan)) {
return FilterResult.included("test plan is empty");
}
if (!object.isTest()) {
if (!object.getChildren().isEmpty()) {
return FilterResult.included("filter only applied for tests");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import io.qameta.allure.aspects.StepsAspects;
import io.qameta.allure.test.AllureResults;
import io.qameta.allure.test.AllureResultsWriterStub;
import io.qameta.allure.testfilter.TestPlan;
import org.junit.platform.engine.discovery.ClassSelector;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestPlan;
import org.junit.platform.launcher.core.LauncherConfig;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
Expand All @@ -44,6 +44,11 @@ private AllureJunitPlatformTestUtils() {

@Step("Run classes {classes}")
public static AllureResults runClasses(final Class<?>... classes) {
return runClasses(null, classes);
}

@Step("Run classes {classes}")
public static AllureResults runClasses(final TestPlan testPlan, final Class<?>... classes) {
final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

Expand All @@ -52,6 +57,7 @@ public static AllureResults runClasses(final Class<?>... classes) {
.toArray(ClassSelector[]::new);

final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.filters(new AllurePostDiscoveryFilter(testPlan))
.selectors(classSelectors)
.build();

Expand All @@ -77,8 +83,9 @@ public static AllureResults runClasses(final Class<?>... classes) {
}

@Step("Build test plan for {classes}")
public static TestPlan buildPlan(final io.qameta.allure.testfilter.TestPlan testPlan,
final Class<?>... classes) {
public static org.junit.platform.launcher.TestPlan buildPlan(
final io.qameta.allure.testfilter.TestPlan testPlan,
final Class<?>... classes) {
final ClassSelector[] classSelectors = Stream.of(classes)
.map(DiscoverySelectors::selectClass)
.toArray(ClassSelector[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/
package io.qameta.allure.junitplatform;

import io.qameta.allure.junitplatform.features.PassedTests;
import io.qameta.allure.junitplatform.features.TestsWithAllureId;
import io.qameta.allure.junitplatform.features.FilterParameterizedTests;
import io.qameta.allure.junitplatform.features.FilterSimpleTests;
import io.qameta.allure.test.AllureResults;
import io.qameta.allure.testfilter.TestPlan;
import io.qameta.allure.testfilter.TestPlanV1_0;
import org.junit.jupiter.api.Test;
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.TestPlan;

import java.util.Arrays;

import static io.qameta.allure.junitplatform.AllureJunitPlatformTestUtils.buildPlan;
import static io.qameta.allure.junitplatform.AllureJunitPlatformTestUtils.runClasses;
import static org.assertj.core.api.Assertions.assertThat;

/**
Expand All @@ -34,79 +34,113 @@ public class AllurePostDiscoveryFilterTest {

@Test
void shouldRunAllTestsIfNoTestPlanProvided() {
final TestPlan testPlan = buildPlan(null, PassedTests.class);
final AllureResults results = runClasses(FilterSimpleTests.class);

final long testsCount = testPlan.countTestIdentifiers(TestIdentifier::isTest);
assertThat(results.getTestResults())
.hasSize(3);
}

@Test
void shouldRunAllParameterizedTestsIfNoTestPlanProvided() {
final AllureResults results = runClasses(FilterParameterizedTests.class);

assertThat(testsCount)
.isEqualTo(3);
assertThat(results.getTestResults())
.hasSize(6);
}

@Test
void shouldRunAllTestsIfEmptyTestPlanProvided() {
final TestPlan testPlan = buildPlan(new TestPlanV1_0(), PassedTests.class);

final long testsCount = testPlan.countTestIdentifiers(TestIdentifier::isTest);
final AllureResults results = runClasses(new TestPlanV1_0(), FilterSimpleTests.class);
assertThat(results.getTestResults())
.hasSize(3);
}

assertThat(testsCount)
.isEqualTo(3);
@Test
void shouldRunAllParameterizedTestsIfEmptyTestPlanProvided() {
final AllureResults results = runClasses(new TestPlanV1_0(), FilterParameterizedTests.class);
assertThat(results.getTestResults())
.hasSize(6);
}

@Test
void shouldFilterTestCasesByFullName() {
final TestPlan testPlan = buildPlan(
new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setSelector("io.qameta.allure.junitplatform.features.PassedTests.second"),
new TestPlanV1_0.TestCase()
.setSelector("io.qameta.allure.junitplatform.features.PassedTests.first")
)),
PassedTests.class
final TestPlan testPlan = new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setSelector(String.format("%s.second", FilterSimpleTests.class.getCanonicalName())),
new TestPlanV1_0.TestCase()
.setSelector(String.format("%s.first", FilterSimpleTests.class.getCanonicalName())))
);

final long testsCount = testPlan.countTestIdentifiers(TestIdentifier::isTest);
final AllureResults results = runClasses(testPlan, FilterSimpleTests.class);
assertThat(results.getTestResults())
.hasSize(2);
}

assertThat(testsCount)
.isEqualTo(2);
@Test
void shouldFilterParameterizedTestCasesByFullName() {
final TestPlan testPlan = new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setSelector(String.format("%s.second", FilterParameterizedTests.class.getCanonicalName())),
new TestPlanV1_0.TestCase()
.setSelector(String.format("%s.first", FilterParameterizedTests.class.getCanonicalName()))
));

final AllureResults results = runClasses(testPlan, FilterParameterizedTests.class);
assertThat(results.getTestResults())
.hasSize(4);
}

@Test
void shouldFilterTestCasesByUniqueId() {
final TestPlan testPlan = buildPlan(
new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setSelector("[engine:junit-jupiter]/[class:io.qameta.allure.junitplatform.features.PassedTests]/[method:second()]"),
new TestPlanV1_0.TestCase()
.setSelector("[engine:junit-jupiter]/[class:io.qameta.allure.junitplatform.features.PassedTests]/[method:third()]")
)),
PassedTests.class
);

final long testsCount = testPlan.countTestIdentifiers(TestIdentifier::isTest);

assertThat(testsCount)
.isEqualTo(2);
final TestPlan testPlan = new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setSelector(testId(FilterSimpleTests.class, "first")),
new TestPlanV1_0.TestCase()
.setSelector(testId(FilterSimpleTests.class, "third"))
));

final AllureResults results = runClasses(testPlan, FilterSimpleTests.class);
assertThat(results.getTestResults())
.hasSize(2);
}

@Test
void shouldFilterTestCasesByAllureId() {
final TestPlan testPlan = buildPlan(
new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setId("32"),
new TestPlanV1_0.TestCase()
.setId("34"),
new TestPlanV1_0.TestCase()
.setId("41"),
new TestPlanV1_0.TestCase()
.setId("48")
)),
TestsWithAllureId.class
);
final TestPlan testPlan = new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setId("10"),
new TestPlanV1_0.TestCase()
.setId("20"),
new TestPlanV1_0.TestCase()
.setId("30")
));

final AllureResults results = runClasses(testPlan, FilterSimpleTests.class);
assertThat(results.getTestResults())
.hasSize(2);
}

@Test
void shouldFilterParameterizedTestCasesByAllureId() {
final TestPlan testPlan = new TestPlanV1_0().setTests(Arrays.asList(
new TestPlanV1_0.TestCase()
.setId("10"),
new TestPlanV1_0.TestCase()
.setId("20")
));

final AllureResults results = runClasses(testPlan, FilterParameterizedTests.class);
assertThat(results.getTestResults())
.hasSize(4);
}

final long testsCount = testPlan.countTestIdentifiers(TestIdentifier::isTest);

assertThat(testsCount)
.isEqualTo(3);
private String testId(final Class<?> testClass, String method) {
return String.format("[engine:%s]/[class:%s]/[method:%s()]",
"junit-jupiter",
testClass.getCanonicalName(),
method);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2019 Qameta Software OÜ
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.junitplatform.features;

import io.qameta.allure.AllureId;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* @author charlie (Dmitry Baev).
*/
public class FilterParameterizedTests {

@BeforeAll
static void doNothing() {

}

@AllureId("10")
@ParameterizedTest
@ValueSource(strings = {"a", "b"})
void first(String value) {
}

@AllureId("20")
@ParameterizedTest
@ValueSource(strings = {"a", "b"})
void second(String value) {
}

@ParameterizedTest
@ValueSource(strings = {"a", "b"})
void third(String value) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2019 Qameta Software OÜ
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.junitplatform.features;

import io.qameta.allure.AllureId;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* @author charlie (Dmitry Baev).
*/
public class FilterSimpleTests {

@BeforeAll
static void doNothing(){

}

@Test
@AllureId("10")
void first() {
}

@Test
@AllureId("20")
void second() {
}

@Test
void third() {
}

}