Skip to content

Commit 328620f

Browse files
author
Julien Herr
committed
Fix #420
1 parent 048a1dc commit 328620f

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ private void invokeConfigurations(IClass testClass,
183183
// Only run the configuration if
184184
// - the test is enabled and
185185
// - the Configuration method belongs to the same class or a parent
186-
if(MethodHelper.isEnabled(objectClass, m_annotationFinder)) {
187-
configurationAnnotation = AnnotationHelper.findConfiguration(m_annotationFinder, method);
186+
configurationAnnotation = AnnotationHelper.findConfiguration(m_annotationFinder, method);
187+
boolean alwaysRun= isAlwaysRun(configurationAnnotation);
188+
if(MethodHelper.isEnabled(objectClass, m_annotationFinder) || alwaysRun) {
188189

189190
if (MethodHelper.isEnabled(configurationAnnotation)) {
190-
boolean alwaysRun= isAlwaysRun(configurationAnnotation);
191191

192192
if (!confInvocationPassed(tm, currentTestMethod, testClass, instance) && !alwaysRun) {
193193
handleConfigurationSkip(tm, testResult, configurationAnnotation, currentTestMethod, instance, suite);
@@ -273,7 +273,11 @@ private boolean isAlwaysRun(IConfigurationAnnotation configurationAnnotation) {
273273
if ((configurationAnnotation.getAfterSuite()
274274
|| configurationAnnotation.getAfterTest()
275275
|| configurationAnnotation.getAfterTestClass()
276-
|| configurationAnnotation.getAfterTestMethod())
276+
|| configurationAnnotation.getAfterTestMethod()
277+
|| configurationAnnotation.getBeforeTestMethod()
278+
|| configurationAnnotation.getBeforeTestClass()
279+
|| configurationAnnotation.getBeforeTest()
280+
|| configurationAnnotation.getBeforeSuite())
277281
&& configurationAnnotation.getAlwaysRun())
278282
{
279283
alwaysRun= true;

src/test/java/test/enable/EnableTest.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,34 @@ public void disabled_methods_should_not_be_run() {
2727
Assert.assertEquals(invokedMethods.get(3), "beforeSuiteNoRunA2");
2828
Assert.assertEquals(invokedMethods.get(4), "beforeSuiteRunA");
2929
Assert.assertEquals(invokedMethods.get(5), "beforeSuiteRunA2");
30-
Assert.assertEquals(invokedMethods.get(6), "beforeSuiteC");
31-
Assert.assertEquals(invokedMethods.get(7), "beforeSuiteC2");
32-
Assert.assertEquals(invokedMethods.get(8), "beforeSuiteNoRunC");
33-
Assert.assertEquals(invokedMethods.get(9), "beforeSuiteNoRunC2");
34-
Assert.assertEquals(invokedMethods.get(10), "beforeSuiteRunC");
35-
Assert.assertEquals(invokedMethods.get(11), "beforeSuiteRunC2");
36-
Assert.assertEquals(invokedMethods.get(12), "testA2");
37-
Assert.assertEquals(invokedMethods.get(13), "testA3");
38-
Assert.assertEquals(invokedMethods.get(14), "testB2");
39-
Assert.assertEquals(invokedMethods.get(15), "testB3");
40-
Assert.assertEquals(invokedMethods.get(16), "testC");
41-
Assert.assertEquals(invokedMethods.get(17), "testC2");
42-
Assert.assertEquals(invokedMethods.get(18), "testC3");
43-
Assert.assertEquals(invokedMethods.size(), 19);
30+
Assert.assertEquals(invokedMethods.get(6), "beforeSuiteRunB");
31+
Assert.assertEquals(invokedMethods.get(7), "beforeSuiteRunB2");
32+
Assert.assertEquals(invokedMethods.get(8), "beforeSuiteC");
33+
Assert.assertEquals(invokedMethods.get(9), "beforeSuiteC2");
34+
Assert.assertEquals(invokedMethods.get(10), "beforeSuiteNoRunC");
35+
Assert.assertEquals(invokedMethods.get(11), "beforeSuiteNoRunC2");
36+
Assert.assertEquals(invokedMethods.get(12), "beforeSuiteRunC");
37+
Assert.assertEquals(invokedMethods.get(13), "beforeSuiteRunC2");
38+
Assert.assertEquals(invokedMethods.get(14), "testA2");
39+
Assert.assertEquals(invokedMethods.get(15), "testA3");
40+
Assert.assertEquals(invokedMethods.get(16), "testB2");
41+
Assert.assertEquals(invokedMethods.get(17), "testB3");
42+
Assert.assertEquals(invokedMethods.get(18), "testC");
43+
Assert.assertEquals(invokedMethods.get(19), "testC2");
44+
Assert.assertEquals(invokedMethods.get(20), "testC3");
45+
Assert.assertEquals(invokedMethods.size(), 21);
4446
}
4547

4648
@Test(description = "https://github.com/cbeust/testng/issues/420")
4749
public void issue420() {
4850
TestNG tng = create(Issue420FirstSample.class, Issue420SecondSample.class);
4951
InvokedMethodListener listener = new InvokedMethodListener();
5052
tng.addListener(listener);
51-
tng.setVerbose(10);
5253
tng.run();
5354

5455
assertThat(listener.getInvokedMethods()).containsExactly(
55-
"initEnvironment", "verifySomethingFirstSample", "verifySomethingSecondSample"
56+
"initEnvironment",
57+
"verifySomethingFirstSample", "verifySomethingSecondSample"
5658
);
5759
}
5860
}

0 commit comments

Comments
 (0)