Fixed: TESTNG-195: @AfterMethod has no way of knowing if the current test failed
diff --git a/CHANGES.txt b/CHANGES.txt
index 0865a9f..42707f6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,7 @@
===========================================================================
5.8.1
+Fixed: TESTNG-195: @AfterMethod has no way of knowing if the current test failed
Added: @BeforeMethod can now declare Object[] as a parameter, which will be filled by the parameters of the test method
Fixed: TESTNG-249: Overridden test methods were shadowing each other if specified with <include>
Fixed: DataProviders from @Factory-created tests were all invoked from the same instance
diff --git a/src/main/org/testng/internal/Invoker.java b/src/main/org/testng/internal/Invoker.java
index 5315b7b..bee93dc 100644
--- a/src/main/org/testng/internal/Invoker.java
+++ b/src/main/org/testng/internal/Invoker.java
@@ -558,6 +558,12 @@
finally {
runInvokedMethodListeners(false, invokedMethod, testResult);
+
+ Class<?>[] expectedExceptionClasses
+ = MethodHelper.findExpectedExceptions(m_annotationFinder, tm.getMethod());
+ List<ITestResult> results = new ArrayList<ITestResult>();
+ results.add(testResult);
+ handleInvocationResults(tm, results, null, 0, expectedExceptionClasses, false);
//
// Increment the invocation count for this method
diff --git a/test/src/test/SimpleBaseTest.java b/test/src/test/SimpleBaseTest.java
index 5c75170..12d3ecd 100644
--- a/test/src/test/SimpleBaseTest.java
+++ b/test/src/test/SimpleBaseTest.java
@@ -9,4 +9,10 @@
result.setVerbose(0);
return result;
}
+
+ protected TestNG create(Class testClass) {
+ TestNG result = create();
+ result.setTestClasses(new Class[] { testClass});
+ return result;
+ }
}
diff --git a/test/src/test/testng195/AfterMethodSampleTest.java b/test/src/test/testng195/AfterMethodSampleTest.java
new file mode 100644
index 0000000..c90e0e3
--- /dev/null
+++ b/test/src/test/testng195/AfterMethodSampleTest.java
@@ -0,0 +1,28 @@
+package test.testng195;
+
+import java.lang.reflect.Method;
+
+import org.testng.IResultMap;
+import org.testng.ITestContext;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class AfterMethodSampleTest {
+ static boolean m_success;
+
+ @Test
+ public void pass() {
+ }
+
+ @BeforeClass
+ public void init() {
+ m_success = false;
+ }
+
+ @AfterMethod
+ public void afterMethod(ITestContext c, Method m) {
+ IResultMap map = c.getPassedTests();
+ m_success = map.size() == 1;
+ }
+}
diff --git a/test/src/test/testng195/AfterMethodTest.java b/test/src/test/testng195/AfterMethodTest.java
new file mode 100644
index 0000000..4b4648b
--- /dev/null
+++ b/test/src/test/testng195/AfterMethodTest.java
@@ -0,0 +1,17 @@
+package test.testng195;
+
+import org.testng.Assert;
+import org.testng.TestNG;
+import org.testng.annotations.Test;
+
+import test.SimpleBaseTest;
+
+public class AfterMethodTest extends SimpleBaseTest {
+
+ @Test
+ public void testContextShouldBeInitialized() {
+ TestNG tng = create(AfterMethodSampleTest.class);
+ tng.run();
+ Assert.assertTrue(AfterMethodSampleTest.m_success);
+ }
+}
diff --git a/test/testng.xml b/test/testng.xml
index 36f6b99..c5f3fe3 100644
--- a/test/testng.xml
+++ b/test/testng.xml
@@ -76,12 +76,14 @@
<class name="test.annotationtransformer.AnnotationTransformerTest" />
<class name="test.configuration.MultipleBeforeGroupTest" />
<class name="test.configuration.BaseGroupsTest" />
+
<!--
<class name="test.jar.JarTest" />
-->
<class name="test.xml.XmlVerifyTest" />
<class name="test.invokedmethodlistener.InvokedMethodListenerTest" />
<class name="test.testng249.VerifyTest"/>
+ <class name="test.testng195.AfterMethodTest" />
</classes>
</test>