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

Fix: alwaysRun should not force invocation of Before-methods #2198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-1622: Parameter alwaysRun=true for before-methods forces execution of those methods (Oleksandr Kulychok)
Fixed: GITHUB-2180: Write scenario details for Retried tests (Devendra Raju K)
Fixed: GITHUB-2124: JUnit Report should contain the output of org.testng.Reporter (Krishnan Mahadevan)
Fixed: GITHUB-2171: Ability to embed attachments and make them available on TestNG XML report (Krishnan Mahadevan)
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/org/testng/internal/ConfigInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,22 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
// - the test is enabled and
// - the Configuration method belongs to the same class or a parent
configurationAnnotation = AnnotationHelper.findConfiguration(annotationFinder(), method);
boolean alwaysRun = MethodHelper.isAlwaysRun(configurationAnnotation);
boolean canProcessMethod =
MethodHelper.isEnabled(objectClass, annotationFinder()) || alwaysRun;
if (!canProcessMethod) {
log(
3,
"Skipping "
+ Utils.detailedMethodName(tm, true)
+ " because "
+ objectClass.getName()
+ " is not enabled");

if (!MethodHelper.isEnabled(objectClass, annotationFinder())) {
log(3, "Skipping " + Utils.detailedMethodName(tm, true) + " because class " +
objectClass.getName() + " is not enabled");
continue;
}
if (MethodHelper.isDisabled(configurationAnnotation)) {
log(3, "Skipping " + Utils.detailedMethodName(tm, true) + " because it is not enabled");
continue;
}

boolean forceRun = MethodHelper.isAlwaysRun(configurationAnnotation) &&
MethodHelper.isAfterMethod(configurationAnnotation);
if (hasConfigurationFailureFor(arguments.getTestMethod(), tm.getGroups() ,
arguments.getTestClass(),
arguments.getInstance()) && !alwaysRun) {
arguments.getInstance()) && !forceRun) {
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
InvokedMethod invokedMethod =
new InvokedMethod(arguments.getInstance(), tm, System.currentTimeMillis(), testResult);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/testng/internal/MethodHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ static boolean isAlwaysRun(IConfigurationAnnotation configurationAnnotation) {
return alwaysRun;
}

/**
* @return true when configurationAnnotation belongs to {@code @After...} method
*/
static boolean isAfterMethod(IConfigurationAnnotation configurationAnnotation) {
if (null == configurationAnnotation) {
return false;
}

return ((configurationAnnotation.getAfterSuite()
|| configurationAnnotation.getAfterTest()
|| configurationAnnotation.getAfterTestClass()
|| configurationAnnotation.getAfterTestMethod()
|| configurationAnnotation.getAfterGroups().length != 0));
}


/** Extracts the unique list of <code>ITestNGMethod</code>s. */
public static List<ITestNGMethod> uniqueMethodList(Collection<List<ITestNGMethod>> methods) {
Set<ITestNGMethod> resultSet = Sets.newHashSet();
Expand Down