Permalink
Browse files

Fixed: TESTNG-102 (Incorrect ordering of @BeforeMethod calls when a d…

…ependency is specified).

Also added tests.
  • Loading branch information...
1 parent 990017e commit ca895efd16c1244e8474a1a135598463bb73c523 cbeust committed Aug 9, 2006
View
1 CHANGES.txt
@@ -1,6 +1,7 @@
===========================================================================
5.1
+Fixed: TESTNG-102 (Incorrect ordering of @BeforeMethod calls when a dependency is specified)
Added: support for specifying test-only classpath (http://forums.opensymphony.com/thread.jspa?messageID=78048&tstart=0)
Fixed: TESTNG-93 (method selectors filtering @BeforeMethod)
Fixed: TESTNG-81 (Assert.assertFalse() displays wrong expected, actual value)
View
19 src/main/org/testng/SuiteRunner.java
@@ -186,9 +186,9 @@ public void run() {
private void privateRun() {
-
- Map<Method, ITestNGMethod> beforeSuiteMethods = new HashMap<Method, ITestNGMethod>();
- Map<Method, ITestNGMethod> afterSuiteMethods = new HashMap<Method, ITestNGMethod>();
+ List<ITestNGMethod> beforeSuiteMethods = new ArrayList<ITestNGMethod>();
+ List<ITestNGMethod> afterSuiteMethods = new ArrayList<ITestNGMethod>();
+// Map<Method, ITestNGMethod> afterSuiteMethods = new HashMap<Method, ITestNGMethod>();
IInvoker invoker = null;
@@ -210,20 +210,22 @@ private void privateRun() {
// TODO: Code smell. Invoker should belong to SuiteRunner, not TestRunner
// -- cbeust
invoker = tr.getInvoker();
-
+
for (ITestNGMethod m : tr.getBeforeSuiteMethods()) {
- beforeSuiteMethods.put(m.getMethod(), m);
+ beforeSuiteMethods.add(m);
}
+
for (ITestNGMethod m : tr.getAfterSuiteMethods()) {
- afterSuiteMethods.put(m.getMethod(), m);
+ afterSuiteMethods.add(m);
+// afterSuiteMethods.put(m.getMethod(), m);
}
}
//
// Invoke beforeSuite methods
//
invoker.invokeConfigurations(null,
- beforeSuiteMethods.values().toArray(new ITestNGMethod[beforeSuiteMethods.size()]),
+ beforeSuiteMethods.toArray(new ITestNGMethod[beforeSuiteMethods.size()]),
m_suite, m_suite.getParameters(),
null /* instance */
);
@@ -252,7 +254,8 @@ private void privateRun() {
// Invoke afterSuite methods
//
invoker.invokeConfigurations(null,
- afterSuiteMethods.values().toArray(new ITestNGMethod[afterSuiteMethods.size()]),
+ afterSuiteMethods.toArray(new ITestNGMethod[afterSuiteMethods.size()]),
+// afterSuiteMethods.values().toArray(new ITestNGMethod[afterSuiteMethods.size()]),
m_suite, m_suite.getAllParameters(),
null /* instance */);
View
22 test/src/test/configuration/BaseSuiteTest.java
@@ -0,0 +1,22 @@
+package test.configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.annotations.BeforeSuite;
+
+public class BaseSuiteTest {
+ public static List<Integer> m_order;
+
+ @BeforeSuite
+ public void beforeSuiteParent(){
+ m_order = new ArrayList<Integer>();
+ m_order.add(1);
+ }
+
+// @AfterSuite
+// public void afterSuiteParent(){
+// m_order.add(5);
+// System.out.println("AFTER SUITE PARENT");
+// }
+}
View
22 test/src/test/configuration/SuiteTest.java
@@ -0,0 +1,22 @@
+package test.configuration;
+
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+public class SuiteTest extends BaseSuiteTest {
+ @BeforeSuite(dependsOnMethods={"beforeSuiteParent"})
+ public void beforeSuiteChild(){
+ m_order.add(2);
+ }
+
+// @AfterSuite(dependsOnMethods={"afterSuiteParent"})
+// public void afterSuiteChild(){
+// m_order.add(4);
+// System.out.println("AFTER SUITE CHILD");
+// }
+
+ @Test
+ public void test1(){
+ m_order.add(3);
+ }
+}
View
14 test/src/test/configuration/VerifySuiteTest.java
@@ -0,0 +1,14 @@
+package test.configuration;
+
+import java.util.Arrays;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterSuite;
+
+public class VerifySuiteTest {
+
+ @AfterSuite
+ public void verify() {
+ Assert.assertEquals(Arrays.asList(1, 2, 3), SuiteTest.m_order);
+ }
+}
View
6 test/testng-single.xml
@@ -1,6 +1,6 @@
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
-<suite name="Single" verbose="9" parallel="false" >
+<suite name="Single" verbose="2" parallel="false" >
<test name="TestSingle">
<!--
@@ -9,9 +9,11 @@
<include name="trial"/>
</run>
</groups>
+ <class name="test.configuration.ExternalConfigurationClass"/>
-->
<classes>
- <class name="test.tmp.A" />
+ <class name="test.configuration.SuiteTest" />
+ <class name="test.configuration.VerifySuiteTest" />
</classes>
</test>
View
2 test/testng.xml
@@ -64,6 +64,8 @@
<class name="test.reports.ReportTest" />
<!-- <class name="test.output.OutputTest" /> -->
<class name="test.configuration.BeforeTestOrderingTest" />
+ <class name="test.configuration.SuiteTest" />
+ <class name="test.configuration.VerifySuiteTest" />
</classes>
</test>

0 comments on commit ca895ef

Please sign in to comment.