Skip to content

Commit c405e94

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

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

CHANGES.txt

+20-19
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)
@@ -481,9 +482,9 @@ Added: Allow injection of java.lang.reflect.Constructor and org.testng.ITestNGMe
481482
Fixed: Assertions in the Assertions class were not failing properly.
482483
Fixed: GITHUB-337: ConfigurationMethod#m_instance set to Boolean.FALSE due to incorrect constructor call in clone() + auto-boxing (davidely)
483484
Fixed: Fix NPE for dependency methods/groups (Krishnan Mahadevan)
484-
Fixed: preserve-order bug (found by VladSarrokhin).
485+
Fixed: preserve-order bug (found by VladSarrokhin).
485486
Fixed: GITHUB-300: OutOfMemoryException from reporters when there are a lot of tests
486-
Fixed: GITHUB-137: Main parameters with a default value should be overridden if a main parameter is specified
487+
Fixed: GITHUB-137: Main parameters with a default value should be overridden if a main parameter is specified
487488
Fixed: GITHUB-107: Allow enum values without converting them to uppercase.
488489
Fixed: @Guice with no modules specified is now supported
489490
Fixed: Reporter.log() invoked from listeners were being discarded
@@ -500,7 +501,7 @@ Added: Big performance improvement when generating the reports (Frank Pavageau)
500501
Added: <dependencies> allows you to specify group dependencies in testng.xml
501502
Added: Blow up early if trying to include/exclude an unknown method
502503
Added: <parameters> can now be specified under <include> (Storm Qi)
503-
Added: GITHUB-243: Add Reporter Output per Test in XMLReporter (dunse)
504+
Added: GITHUB-243: Add Reporter Output per Test in XMLReporter (dunse)
504505
Fixed: Better HTML escaping of the stack traces
505506
Fixed: The failed assertions now use [] as delimiters instead of <> (better for the HTML reports)
506507
Fixed: GITHUB-237: Wrong time format in XML reporter
@@ -685,7 +686,7 @@ Eclipse:
685686
Added: New quick fix "Add static import org.testng.AssertJUnit.assertXXX"
686687
Added: New workspace wide setting: excluded stack traces, to provide shorter stack traces in the view
687688
Added: New "Clear results" icon in the tool bar
688-
Added: When the search filter is modified, don't update the tree live if it is too big
689+
Added: When the search filter is modified, don't update the tree live if it is too big
689690
Added: Two new @Test refactorings (pull to class level, push to method level)
690691
Added: JUnit conversion: @Ignore
691692
Added: JUnit conversion: assertArrayEquals()
@@ -829,10 +830,10 @@ Added: -testnames (command line) and testnames (ant)
829830
Added: New ant task tag: propertyset (Todd Wells)
830831
Added: ITestNGListenerFactory
831832
Added: Passing command line properties via the ant task and doc update (Todd Wells)
832-
Added: Hierarchical XmlSuites (Nalin Makar)
833+
Added: Hierarchical XmlSuites (Nalin Makar)
833834
Added: Reporter#clear()
834835
Fixed: NullPointerException when a suite produces no results (Cefn Hoile)
835-
Fixed: Identical configuration methods were not always invoked in the correct order in superclasses (Nalin Makar)
836+
Fixed: Identical configuration methods were not always invoked in the correct order in superclasses (Nalin Makar)
836837
Fixed: @DataProvider(parallel = true) was passing incorrect parameters with injection
837838
Fixed: Replaced @Test(sequential) with @Test(singleThreaded)
838839
Fixed: If inherited configuration methods had defined deps, they could be invoked in incorrect order (Nalin Makar)
@@ -849,9 +850,9 @@ Fixed: Issue78 NPE with non-public class. Now throws TestNG exception
849850
Fixed: NPE with @Optional null parameters (Yves Dessertine)
850851
Fixed: TESTNG-387 TestNG not rerunning test method with the right data set from Data Provider (Francois Reynaud)
851852
Fixed: Show correct number of pass/failed numbers for tests using @DataProvider
852-
Fixed: Return correct method status and exception (if any) in InvokedMethodListener.afterInvocation()
853-
Fixed: Trivial fixes: TESTNG-241 (log message at Info), Issue2 (throw SAXException and not NPE for invalid testng xml)
854-
Fixed: Configuration methods couldn't depend on an abstract method (Nalin Makar)
853+
Fixed: Return correct method status and exception (if any) in InvokedMethodListener.afterInvocation()
854+
Fixed: Trivial fixes: TESTNG-241 (log message at Info), Issue2 (throw SAXException and not NPE for invalid testng xml)
855+
Fixed: Configuration methods couldn't depend on an abstract method (Nalin Makar)
855856
Fixed: TestNG#setTestClasses was not resetting m_suites
856857
Fixed: Exceptions thrown by IInvokedMethodListeners were not caught (Nalin Makar)
857858
Fixed: @Listeners now works on base classes as well
@@ -966,8 +967,8 @@ Fixed: Quick fixes no longer introduce deprecated annotations (Greg Turnquist)
966967
5.9
967968
2009/04/09
968969

969-
Added: New ant task boolean flag: delegateCommandSystemProperties (Justin)
970-
Added: skipfailedinvocations under <suite> in testng-1.0.dtd (Gael Marziou / Stevo Slavic)
970+
Added: New ant task boolean flag: delegateCommandSystemProperties (Justin)
971+
Added: skipfailedinvocations under <suite> in testng-1.0.dtd (Gael Marziou / Stevo Slavic)
971972
Added: -testrunfactory on the command line and in the ant task (Vitalyi Pamajonkov)
972973
Added: TESTNG-298: parallel="classes", which allows entire classes to be run in the same thread
973974
Added: @BeforeMethod can now declare Object[] as a parameter, which will be filled by the parameters of the test method
@@ -1060,7 +1061,7 @@ Added: ISuite now gives access to the current XmlSuite
10601061
Fixed: TESTNG-139 dependsOnMethods gets confused when dependency is "protected"
10611062
Fixed: TESTNG-141 junit attribute set to false in testng-failed.xml when it should be true
10621063
Fixed: TESTNG-142 Exceptions in DataProvider are not reported as failed test
1063-
Added: Improved behavior for @Before/@AfterClass when using @Factory
1064+
Added: Improved behavior for @Before/@AfterClass when using @Factory
10641065
(http://forums.opensymphony.com/thread.jspa?threadID=6594&messageID=122294#122294)
10651066
Added: Support for concurrent execution for invocationCount=1 threadPoolSize>1 and @DataProvider
10661067
(http://forums.opensymphony.com/thread.jspa?threadID=64738&tstart=0)
@@ -1096,7 +1097,7 @@ Added: Method selectors receive a Context and can stop the chain with setStopped
10961097
Fixed: XmlMethodSelector was always run first regardless of its priority
10971098
Added: @BeforeGroups/@AfterGroups can live in classes without @Test methods
10981099
Added: DataProvider can now take an ITestContext parameter
1099-
Fixed: Wasn't parsing <selector-class-name> correctly
1100+
Fixed: Wasn't parsing <selector-class-name> correctly
11001101
Fixed: Annotation Transformers now work on class-level annotations
11011102
Fixed: Some class-level @Test attributes were not always honored
11021103
Added: Clean separation between @Test invocation events and @Configuration invocation events
@@ -1133,7 +1134,7 @@ Eclipse plug-in
11331134
Fixed: groups with multi-attribute javadoc annotations
11341135
Fixed: consistent behavior for dependsOnMethods
11351136
Fixed: consistent behavior for tests with dependsOnGroups (a warning is emitted)
1136-
Fixed: consistent merge of configuration arguments when an existing launch configuration exists
1137+
Fixed: consistent merge of configuration arguments when an existing launch configuration exists
11371138
===========================================================================
11381139
5.3
11391140
2006/10/30
@@ -1237,7 +1238,7 @@ Added: Can now specify listener classes
12371238
5.0.1
12381239

12391240
Fixed: reports generated by SuiteHTMLReporter do not work with JDK1.4
1240-
1241+
12411242
===========================================================================
12421243

12431244
5.0
@@ -1323,7 +1324,7 @@ Fixed: TESTNG-18: Eclipse plugin ignores Factory annotation
13231324
Fixed: TESTNG-21: Show differences when double clicking assertion exceptions
13241325
Added: UI allows setting orientation (even more space)
13251326
http://forums.opensymphony.com/thread.jspa?threadID=17225&messageID=33805#33805
1326-
1327+
13271328
===========================================================================
13281329

13291330
4.5
@@ -1426,7 +1427,7 @@ Fixed: dependsOnGroups wasn't working on regular expressions
14261427
Fixed: Bug in <package> when directories contain spaces in their names
14271428
Fixed: Introduced a JDK5 dependency in the JDK1.4 build (getEnclosingClass())
14281429
Fixed: Output directory in ant task was not honored if it didn't exist
1429-
Fixed: Problem with timeout according to
1430+
Fixed: Problem with timeout according to
14301431
http://forums.opensymphony.com/thread.jspa?threadID=6707
14311432

14321433
Eclipse plug-in:
@@ -1436,7 +1437,7 @@ Fixed: Bug in QuickFix implementation
14361437
Added: Quick Fix for JUnit conversion (Annotations and JavaDoc)
14371438
Fixed: Methods Run as TestNG test
14381439
Added: Package level Run as TestNG test
1439-
Fixed: Resources from the linked directories are using a wrong path when
1440+
Fixed: Resources from the linked directories are using a wrong path when
14401441
passed to command line TestNG
14411442

14421443
IDEA plug-in:
@@ -1501,7 +1502,7 @@ Fixed: TestNGException thrown when TestNG conditions are not fulfilled
15011502

15021503
Documentation:
15031504
- New assert classes
1504-
- New ways to launch
1505+
- New ways to launch
15051506
- JUnitConverter documentation
15061507
- new beforeSuite/afterSuite
15071508

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

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package org.testng.internal;
22

3-
import static org.testng.internal.Invoker.SAME_CLASS;
4-
import static org.testng.internal.invokers.InvokedMethodListenerMethod.AFTER_INVOCATION;
5-
import static org.testng.internal.invokers.InvokedMethodListenerMethod.BEFORE_INVOCATION;
6-
73
import java.lang.reflect.InvocationTargetException;
84
import java.util.Arrays;
95
import java.util.Collection;
106
import java.util.List;
117
import java.util.Map;
128
import java.util.Set;
139
import java.util.concurrent.ConcurrentHashMap;
10+
1411
import org.testng.IClass;
1512
import org.testng.IConfigurable;
1613
import org.testng.IInvokedMethodListener;
@@ -30,6 +27,10 @@
3027
import org.testng.xml.XmlClass;
3128
import org.testng.xml.XmlSuite;
3229

30+
import static org.testng.internal.Invoker.SAME_CLASS;
31+
import static org.testng.internal.invokers.InvokedMethodListenerMethod.AFTER_INVOCATION;
32+
import static org.testng.internal.invokers.InvokedMethodListenerMethod.BEFORE_INVOCATION;
33+
3334
class ConfigInvoker extends BaseInvoker implements IConfigInvoker {
3435

3536
/**
@@ -239,26 +240,22 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
239240
// - the test is enabled and
240241
// - the Configuration method belongs to the same class or a parent
241242
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");
243+
244+
if (!MethodHelper.isEnabled(objectClass, annotationFinder())) {
245+
log(3, "Skipping " + Utils.detailedMethodName(tm, true) + " because class " +
246+
objectClass.getName() + " is not enabled");
253247
continue;
254248
}
255249
if (MethodHelper.isDisabled(configurationAnnotation)) {
256250
log(3, "Skipping " + Utils.detailedMethodName(tm, true) + " because it is not enabled");
257251
continue;
258252
}
253+
254+
boolean forceRun = MethodHelper.isAlwaysRun(configurationAnnotation) &&
255+
MethodHelper.isAfterMethod(configurationAnnotation);
259256
if (hasConfigurationFailureFor(arguments.getTestMethod(), tm.getGroups() ,
260257
arguments.getTestClass(),
261-
arguments.getInstance()) && !alwaysRun) {
258+
arguments.getInstance()) && !forceRun) {
262259
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
263260
InvokedMethod invokedMethod =
264261
new InvokedMethod(arguments.getInstance(), tm, System.currentTimeMillis(), testResult);

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import java.util.Set;
1212
import java.util.concurrent.ConcurrentHashMap;
1313
import java.util.regex.Pattern;
14-
1514
import java.util.stream.Collectors;
15+
1616
import org.testng.IInvokedMethod;
1717
import org.testng.IMethodInstance;
1818
import org.testng.ITestClass;
@@ -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)