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

Support class level config failure policy #2869

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
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Current
Fixed: GITHUB-2771: After upgrading to TestNG 7.5.0, setting ITestResult.status to FAILURE doesn't fail the test anymore (Julien Herr & Krishnan Mahadevan)
Fixed: GITHUB-2796: Option for onAfterClass to run after @AfterClass
Fixed: GITHUB-2857: XmlTest index is not set for test suites invoked with YAML
Fixed: GITHUB-2862: Allow test classes to define "configfailurepolicy" at a per class level (Krishnan Mahadevan)
Fixed: GITHUB-2796: Option for onAfterClass to run after @AfterClass (Oliver Hughes)
Fixed: GITHUB-2857: XmlTest index is not set for test suites invoked with YAML (Sergei Baranov)

7.7.1
Fixed: GITHUB-2854: overloaded assertEquals methods do not work from Groovy (Krishnan Mahadevan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public static <K> List<K> newArrayList(K... elements) {
return result;
}

@SafeVarargs
public static <K> List<K> newArrayList(K[]... elements) {
return Arrays.stream(elements)
.map(Arrays::asList)
.flatMap(Collection::stream)
.collect(Collectors.toList());
}

public static <K> List<K> newArrayList(int size) {
return new ArrayList<>(size);
}
Expand Down
8 changes: 8 additions & 0 deletions testng-core-api/src/main/java/org/testng/ITestNGMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,12 @@ default IDataProviderMethod getDataProviderMethod() {
default Class<?>[] getParameterTypes() {
return new Class<?>[] {};
}

/**
* @return - <code>true</code> if the configuration failure arising out of this method should be
* ignored.
*/
default boolean isIgnoreFailure() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* @return - <code>true</code> if the configuration failure arising out of this method should be
* ignored. Enabling this will override the "configfailurepolicy" set at the suite level ONLY
* for this method.
*/
boolean ignoreFailure() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* @return - <code>true</code> if the configuration failure arising out of this method should be
* ignored. Enabling this will override the "configfailurepolicy" set at the suite level ONLY
* for this method.
*/
boolean ignoreFailure() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* @return - <code>true</code> if the configuration failure arising out of this method should be
* ignored. Enabling this will override the "configfailurepolicy" set at the suite level ONLY
* for this method.
*/
boolean ignoreFailure() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ default boolean isBeforeGroups() {
default boolean isAfterGroups() {
return false;
}

boolean isIgnoreFailure();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ConfigurationMethod extends BaseTestMethod {
private boolean m_isBeforeGroupsConfiguration;
private boolean m_isAfterGroupsConfiguration;

private final boolean m_isIgnoreFailure;
private boolean m_inheritGroupsFromTestClass = false;
private final IParameterInfo factoryMethodInfo;

Expand All @@ -61,6 +62,7 @@ private ConfigurationMethod(
boolean isAfterClass,
boolean isBeforeMethod,
boolean isAfterMethod,
boolean isIgnoreFailure,
String[] beforeGroups,
String[] afterGroups,
boolean initialize,
Expand Down Expand Up @@ -90,6 +92,8 @@ private ConfigurationMethod(
m_isBeforeMethodConfiguration = isBeforeMethod;
m_isAfterMethodConfiguration = isAfterMethod;

m_isIgnoreFailure = isIgnoreFailure;

m_beforeGroups = beforeGroups;
m_afterGroups = afterGroups;
}
Expand All @@ -114,6 +118,7 @@ public ConfigurationMethod(
boolean isAfterClass,
boolean isBeforeMethod,
boolean isAfterMethod,
boolean isIgnoreFailure,
String[] beforeGroups,
String[] afterGroups,
XmlTest xmlTest,
Expand All @@ -130,6 +135,7 @@ public ConfigurationMethod(
isAfterClass,
isBeforeMethod,
isAfterMethod,
isIgnoreFailure,
beforeGroups,
afterGroups,
true,
Expand Down Expand Up @@ -175,6 +181,7 @@ private static ITestNGMethod[] createMethods(
isAfterClass,
isBeforeMethod,
isAfterMethod,
method.isIgnoreFailure(),
new String[0],
new String[0],
xmlTest,
Expand Down Expand Up @@ -274,6 +281,7 @@ public static ITestNGMethod[] createBeforeConfigurationMethods(
false,
false,
false,
false,
isBefore ? methods[i].getBeforeGroups() : new String[0],
new String[0],
null,
Expand Down Expand Up @@ -305,6 +313,7 @@ public static ITestNGMethod[] createAfterConfigurationMethods(
false,
false,
false,
false,
new String[0],
isBefore ? m.getBeforeGroups() : m.getAfterGroups(),
null,
Expand Down Expand Up @@ -398,6 +407,11 @@ public boolean isAfterGroupsConfiguration() {
return m_afterGroups != null && m_afterGroups.length > 0;
}

@Override
public boolean isIgnoreFailure() {
return this.m_isIgnoreFailure;
}

private boolean inheritGroupsFromTestClass() {
return m_inheritGroupsFromTestClass;
}
Expand Down Expand Up @@ -489,6 +503,7 @@ public ConfigurationMethod clone() {
isAfterClassConfiguration(),
isBeforeMethodConfiguration(),
isAfterMethodConfiguration(),
isIgnoreFailure(),
getBeforeGroups(),
getAfterGroups(),
false /* do not call init() */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private ITestNGMethod[] findConfiguration(
}

if (create) {
boolean ignoreFailure = configuration.isIgnoreFailure();
addConfigurationMethod(
clazz,
vResult,
Expand All @@ -200,6 +201,7 @@ private ITestNGMethod[] findConfiguration(
isAfterClass,
isBeforeTestMethod,
isAfterTestMethod,
ignoreFailure,
beforeGroups,
afterGroups); /* @@@ */
}
Expand Down Expand Up @@ -241,6 +243,7 @@ private void addConfigurationMethod(
boolean isAfterClass,
boolean isBeforeTestMethod,
boolean isAfterTestMethod,
boolean isIgnoreFailure,
String[] beforeGroups,
String[] afterGroups) {
if (method.getDeclaringClass().isAssignableFrom(clazz)) {
Expand All @@ -257,6 +260,7 @@ private void addConfigurationMethod(
isAfterClass,
isBeforeTestMethod,
isAfterTestMethod,
isIgnoreFailure,
beforeGroups,
afterGroups,
this.runInfo.getXmlTest(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ public static IFactoryAnnotation findFactory(IAnnotationFinder finder, Construct
public static IConfigurationAnnotation findConfiguration(
IAnnotationFinder finder, ConstructorOrMethod m) {
IConfigurationAnnotation result = null;
boolean ignoreFailure = false;
IConfigurationAnnotation bs =
(IConfigurationAnnotation) finder.findAnnotation(m, IBeforeSuite.class);
IConfigurationAnnotation as =
(IConfigurationAnnotation) finder.findAnnotation(m, IAfterSuite.class);
IConfigurationAnnotation bt =
(IConfigurationAnnotation) finder.findAnnotation(m, IBeforeTest.class);
if (bt != null) {
ignoreFailure = bt.isIgnoreFailure();
}
IConfigurationAnnotation at =
(IConfigurationAnnotation) finder.findAnnotation(m, IAfterTest.class);
IConfigurationAnnotation bg =
Expand All @@ -100,10 +104,16 @@ public static IConfigurationAnnotation findConfiguration(
(IConfigurationAnnotation) finder.findAnnotation(m, IAfterGroups.class);
IConfigurationAnnotation bc =
(IConfigurationAnnotation) finder.findAnnotation(m, IBeforeClass.class);
if (bc != null) {
ignoreFailure = bc.isIgnoreFailure();
}
IConfigurationAnnotation ac =
(IConfigurationAnnotation) finder.findAnnotation(m, IAfterClass.class);
IConfigurationAnnotation bm =
(IConfigurationAnnotation) finder.findAnnotation(m, IBeforeMethod.class);
if (bm != null) {
ignoreFailure = bm.isIgnoreFailure();
}
IConfigurationAnnotation am =
(IConfigurationAnnotation) finder.findAnnotation(m, IAfterMethod.class);

Expand All @@ -120,6 +130,10 @@ public static IConfigurationAnnotation findConfiguration(
result = createConfiguration(bs, as, bt, at, bg, ag, bc, ac, bm, am);
}

if (result instanceof ConfigurationAnnotation) {
((ConfigurationAnnotation) result).setIgnoreFailure(ignoreFailure);
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ConfigurationAnnotation extends TestOrConfiguration
private boolean m_isFakeConfiguration;
private boolean m_firstTimeOnly = false;
private boolean m_lastTimeOnly = false;
private boolean m_ignoreFailure = false;

public ConfigurationAnnotation() {}

Expand Down Expand Up @@ -196,4 +197,12 @@ public void setLastTimeOnly(boolean f) {
public boolean isLastTimeOnly() {
return m_lastTimeOnly;
}

public boolean isIgnoreFailure() {
return m_ignoreFailure;
}

public void setIgnoreFailure(boolean ignoreFailure) {
this.m_ignoreFailure = ignoreFailure;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public interface IBaseBeforeAfter extends ITestOrConfiguration {
* standard output if verbose &gt; 2.
*/
String getDescription();

default boolean ignoreFailure() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
new String[0]);
new String[0],
bs.ignoreFailure());
} else if (annotationClass == IAfterTest.class) {
AfterTest bs = (AfterTest) a;
result =
Expand Down Expand Up @@ -273,7 +274,8 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
new String[0]);
new String[0],
bs.ignoreFailure());
} else if (annotationClass == IAfterClass.class) {
AfterClass bs = (AfterClass) a;
result =
Expand Down Expand Up @@ -327,7 +329,8 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
bs.firstTimeOnly(),
false,
bs.timeOut(),
bs.onlyForGroups());
bs.onlyForGroups(),
bs.ignoreFailure());
} else if (annotationClass == IAfterMethod.class) {
AfterMethod bs = (AfterMethod) a;
result =
Expand Down Expand Up @@ -384,6 +387,58 @@ private IAnnotation createConfigurationTag(
boolean lastTimeOnly,
long timeOut,
String[] groupFilters) {
return createConfigurationTag(
beforeSuite,
afterSuite,
beforeTest,
afterTest,
beforeGroups,
isBeforeGroups,
afterGroups,
isAfterGroups,
beforeClass,
afterClass,
beforeMethod,
afterMethod,
alwaysRun,
dependsOnGroups,
dependsOnMethods,
description,
enabled,
groups,
inheritGroups,
firstTimeOnly,
lastTimeOnly,
timeOut,
groupFilters,
false);
}

private IAnnotation createConfigurationTag(
boolean beforeSuite,
boolean afterSuite,
boolean beforeTest,
boolean afterTest,
String[] beforeGroups,
boolean isBeforeGroups,
String[] afterGroups,
boolean isAfterGroups,
boolean beforeClass,
boolean afterClass,
boolean beforeMethod,
boolean afterMethod,
boolean alwaysRun,
String[] dependsOnGroups,
String[] dependsOnMethods,
String description,
boolean enabled,
String[] groups,
boolean inheritGroups,
boolean firstTimeOnly,
boolean lastTimeOnly,
long timeOut,
String[] groupFilters,
boolean ignoreFailure) {
ConfigurationAnnotation result = new ConfigurationAnnotation();
result.setIsBeforeGroups(isBeforeGroups);
result.setIsAfterGroups(isAfterGroups);
Expand All @@ -410,7 +465,7 @@ private IAnnotation createConfigurationTag(
result.setFirstTimeOnly(firstTimeOnly);
result.setLastTimeOnly(lastTimeOnly);
result.setTimeOut(timeOut);

result.setIgnoreFailure(ignoreFailure);
return result;
}

Expand Down
Loading