Skip to content

Commit 66062ab

Browse files
committed
Fix: alwaysRun should not force invocation of Before-methods
Resolves testng-team#1622
1 parent acf96cc commit 66062ab

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current
2+
Fixed: GITHUB-1622: Parameter alwaysRun=true for before-methods forces execution of those methods (Oleksandr Kulychok)
23
Fixed: GITHUB-2180: Write scenario details for Retried tests (Devendra Raju K)
34
Fixed: GITHUB-2124: JUnit Report should contain the output of org.testng.Reporter (Krishnan Mahadevan)
45
Fixed: GITHUB-2171: Ability to embed attachments and make them available on TestNG XML report (Krishnan Mahadevan)

src/main/java/org/testng/internal/ConfigInvoker.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,22 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
239239
// - the test is enabled and
240240
// - the Configuration method belongs to the same class or a parent
241241
configurationAnnotation = AnnotationHelper.findConfiguration(annotationFinder(), method);
242-
boolean alwaysRun = MethodHelper.isAlwaysRun(configurationAnnotation);
243-
boolean canProcessMethod =
244-
MethodHelper.isEnabled(objectClass, annotationFinder()) || alwaysRun;
245-
if (!canProcessMethod) {
246-
log(
247-
3,
248-
"Skipping "
249-
+ Utils.detailedMethodName(tm, true)
250-
+ " because "
251-
+ objectClass.getName()
252-
+ " is not enabled");
242+
243+
if (!MethodHelper.isEnabled(objectClass, annotationFinder())) {
244+
log(3, "Skipping " + Utils.detailedMethodName(tm, true) + " because class " +
245+
objectClass.getName() + " is not enabled");
253246
continue;
254247
}
255248
if (MethodHelper.isDisabled(configurationAnnotation)) {
256249
log(3, "Skipping " + Utils.detailedMethodName(tm, true) + " because it is not enabled");
257250
continue;
258251
}
252+
253+
boolean forceRun = MethodHelper.isAlwaysRun(configurationAnnotation) &&
254+
MethodHelper.isAfterMethod(configurationAnnotation);
259255
if (hasConfigurationFailureFor(arguments.getTestMethod(), tm.getGroups() ,
260256
arguments.getTestClass(),
261-
arguments.getInstance()) && !alwaysRun) {
257+
arguments.getInstance()) && !forceRun) {
262258
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
263259
InvokedMethod invokedMethod =
264260
new InvokedMethod(arguments.getInstance(), tm, System.currentTimeMillis(), testResult);

src/main/java/org/testng/internal/MethodHelper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ static boolean isAlwaysRun(IConfigurationAnnotation configurationAnnotation) {
226226
return alwaysRun;
227227
}
228228

229+
/**
230+
* @return true when configurationAnnotation belongs to {@code @After...} method
231+
*/
232+
static boolean isAfterMethod(IConfigurationAnnotation configurationAnnotation) {
233+
if (null == configurationAnnotation) {
234+
return false;
235+
}
236+
237+
return ((configurationAnnotation.getAfterSuite()
238+
|| configurationAnnotation.getAfterTest()
239+
|| configurationAnnotation.getAfterTestClass()
240+
|| configurationAnnotation.getAfterTestMethod()
241+
|| configurationAnnotation.getAfterGroups().length != 0));
242+
}
243+
244+
229245
/** Extracts the unique list of <code>ITestNGMethod</code>s. */
230246
public static List<ITestNGMethod> uniqueMethodList(Collection<List<ITestNGMethod>> methods) {
231247
Set<ITestNGMethod> resultSet = Sets.newHashSet();

0 commit comments

Comments
 (0)