Skip to content

Commit

Permalink
Raise minimum required TestNG version to 6.14.3
Browse files Browse the repository at this point in the history
Earlier versions did not support dry-run mode which led to test being
executed multiple times (during discovery and execution).
  • Loading branch information
marcphilipp committed Jul 17, 2021
1 parent c9d3402 commit 94da065
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:jquery-version: 3.5.1
:junit-platform-version: 1.7.2
:surefire-version: 3.0.0-M5
:testng-min-version: 6.9.13.6
:testng-min-version: 6.14.3
:testng-max-version: 7.4.0
:testng-engine-version: 1.0.0-M2

Expand Down
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ configurations {
}

val supportedTestNGVersions = listOf(
"6.9.13.6",
"6.10",
"6.11",
"6.13.1",
"6.14.3",
"7.0.0",
"7.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@

package org.junit.support.testng.engine;

import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.testkit.engine.EventConditions.abortedWithReason;
import static org.junit.platform.testkit.engine.EventConditions.engine;
import static org.junit.platform.testkit.engine.EventConditions.event;
import static org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully;
import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure;
import static org.junit.platform.testkit.engine.EventConditions.skippedWithReason;
import static org.junit.platform.testkit.engine.EventConditions.started;
import static org.junit.platform.testkit.engine.EventConditions.test;
import static org.junit.platform.testkit.engine.TestExecutionResultConditions.message;

import java.lang.annotation.Retention;

import example.configuration.FailingAfterClassConfigurationMethodTestCase;
import example.configuration.FailingAfterMethodConfigurationMethodTestCase;
import example.configuration.FailingAfterSuiteConfigurationMethodTestCase;
Expand Down Expand Up @@ -51,23 +47,6 @@ void reportsFailureFromBeforeClassMethod() {
}

@Test
@RequiresTestNGVersion(max = "6.10")
void reportsFailureFromBeforeMethodConfigurationMethodAsAbortedWithoutThrowable() {
var testClass = FailingBeforeMethodConfigurationMethodTestCase.class;

var results = testNGEngine().selectors(selectClass(testClass)).execute();

results.allEvents().assertEventsMatchLooselyInOrder( //
event(testClass(testClass), started()), //
event(test("method:a()"), started()), //
event(test("method:a()"), finishedSuccessfully()), //
event(test("method:b()"), started()), //
event(test("method:b()"), abortedWithReason()), //
event(testClass(testClass), finishedWithFailure(message("boom"))));
}

@Test
@RequiresTestNGVersion(min = "6.11")
void reportsFailureFromBeforeMethodConfigurationMethodAsAbortedWithThrowable() {
var testClass = FailingBeforeMethodConfigurationMethodTestCase.class;

Expand All @@ -82,41 +61,10 @@ void reportsFailureFromBeforeMethodConfigurationMethodAsAbortedWithThrowable() {
event(testClass(testClass), finishedWithFailure(message("boom"))));
}

@Test
@RequiresTestNGVersion(max = "6.10")
void reportsFailureFromBeforeTestMethodAsAbortedWithoutThrowable() {
var testClass = FailingBeforeTestConfigurationMethodTestCase.class;

var results = testNGEngine().selectors(selectClass(testClass)).execute();

results.allEvents().assertEventsMatchExactly( //
event(engine(), started()), //
event(testClass(testClass), started()), //
event(test("method:test()"), started()), //
event(test("method:test()"), abortedWithReason()), //
event(testClass(testClass), finishedSuccessfully()), //
event(engine(), finishedWithFailure(message("boom"))));
}

@Test
@RequiresTestNGVersion(max = "6.9.13.6")
void reportsFailureFromBeforeSuiteMethodAsSkipped() {
var testClass = FailingBeforeSuiteConfigurationMethodTestCase.class;

var results = testNGEngine().selectors(selectClass(testClass)).execute();

results.allEvents().assertEventsMatchExactly( //
event(engine(), started()), //
event(testClass(testClass), started()), //
event(test("method:test()"), skippedWithReason(__ -> true)), //
event(testClass(testClass), finishedSuccessfully()), //
event(engine(), finishedWithFailure(message("boom"))));
}

@ParameterizedTest
@TestCasesWithEarlyEngineLevelConfigurationMethodFailures
@RequiresTestNGVersion(min = "6.10")
void reportsFailureFromEarlyEngineLevelConfigurationMethodAsAbortedWithThrowable(Class<?> testClass) {
@ValueSource(classes = { FailingBeforeTestConfigurationMethodTestCase.class,
FailingBeforeSuiteConfigurationMethodTestCase.class })
void reportsFailureFromEarlyEngineLevelConfigurationMethodAsAborted(Class<?> testClass) {
var results = testNGEngine().selectors(selectClass(testClass)).execute();

results.allEvents().debug().assertEventsMatchExactly( //
Expand All @@ -142,7 +90,8 @@ void reportsFailureFromAfterMethodConfigurationMethodAsClassLevelFailure() {
}

@ParameterizedTest
@TestCasesWithLateEngineLevelConfigurationMethodFailures
@ValueSource(classes = { FailingAfterClassConfigurationMethodTestCase.class,
FailingAfterTestConfigurationMethodTestCase.class, FailingAfterSuiteConfigurationMethodTestCase.class })
void reportsFailureFromLateEngineLevelConfigurationMethodAsEngineLevelFailure(Class<?> testClass) {
var results = testNGEngine().selectors(selectClass(testClass)).execute();

Expand All @@ -155,16 +104,4 @@ void reportsFailureFromLateEngineLevelConfigurationMethodAsEngineLevelFailure(Cl
event(engine(), finishedWithFailure(message("boom"))));
}

@Retention(RUNTIME)
@ValueSource(classes = { FailingBeforeTestConfigurationMethodTestCase.class,
FailingBeforeSuiteConfigurationMethodTestCase.class })
@interface TestCasesWithEarlyEngineLevelConfigurationMethodFailures {
}

@Retention(RUNTIME)
@ValueSource(classes = { FailingAfterClassConfigurationMethodTestCase.class,
FailingAfterTestConfigurationMethodTestCase.class, FailingAfterSuiteConfigurationMethodTestCase.class })
@interface TestCasesWithLateEngineLevelConfigurationMethodFailures {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.regex.Pattern;

import example.basics.DryRunTestCase;
import example.basics.IgnoredTestCase;
import example.basics.InheritedClassLevelOnlyAnnotationTestCase;
import example.basics.InheritingSubClassTestCase;
Expand All @@ -53,6 +54,20 @@ class DiscoveryIntegrationTests extends AbstractIntegrationTests {
private final TestNGTestEngine testEngine = new TestNGTestEngine();
private final UniqueId engineId = UniqueId.forEngine(testEngine.getId());

@Test
void discoveryDoesNotRunTests() {
var testClass = DryRunTestCase.class;
DryRunTestCase.INVOCATIONS = 0;
var request = request().selectors(selectClass(testClass)).build();

var rootDescriptor = testEngine.discover(request, engineId);

assertThat(DryRunTestCase.INVOCATIONS).isEqualTo(0);
TestDescriptor classDescriptor = getOnlyElement(rootDescriptor.getChildren());
TestDescriptor methodDescriptor = getOnlyElement(classDescriptor.getChildren());
assertThat(methodDescriptor.getChildren()).isEmpty();
}

@ParameterizedTest
@ValueSource(classes = { SimpleTestCase.class, InheritingSubClassTestCase.class })
void discoversAllTestMethodsForClassSelector(Class<?> testClass) {
Expand Down Expand Up @@ -251,7 +266,6 @@ void discoversTestMethodsWithMultipleInvocationsAsContainers() {
}

@Test
@RequiresTestNGVersion(min = "6.13") // introduced in 6.13
void ignoresIgnoredTests() {
var request = request().selectors(selectClass(IgnoredTestCase.class)).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ void reportsRetriedTestsWithDataProvidersCorrectly() {

@ParameterizedTest
@ValueSource(strings = { "timeOut", "invocationTimeOut" })
@RequiresTestNGVersion(except = "6.11") // https://github.com/cbeust/testng/issues/1493
void reportsTimedOutTestsAsFailures(String methodName) {
var testClass = TimeoutTestCase.class;

Expand Down
24 changes: 24 additions & 0 deletions src/testFixtures/java/example/basics/DryRunTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2021 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package example.basics;

import org.testng.annotations.Test;

public class DryRunTestCase {

public static int INVOCATIONS;

@Test
public void test() {
INVOCATIONS++;
}

}

0 comments on commit 94da065

Please sign in to comment.