Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: onTestSuccess() was called after @AfterMethod instead of after…
… the test method (test: test.listener.ListenerTest)
- Loading branch information
cbeust
committed
Jun 27, 2010
1 parent
37d27f3
commit 721fb91
Showing
5 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.listeners; | ||
|
||
import java.util.Arrays; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.testng.TestNG; | ||
import org.testng.annotations.Test; | ||
|
||
import test.SimpleBaseTest; | ||
|
||
public class ListenerTest extends SimpleBaseTest { | ||
|
||
/** | ||
* Ensure that if a listener is present, we get test(), onSuccess(), afterMethod() | ||
*/ | ||
@Test | ||
public void listenerShouldBeCalledBeforeConfiguration() { | ||
TestNG tng = create(OrderedListenerSampleTest.class); | ||
tng.run(); | ||
Assert.assertEquals(Arrays.asList(1, 2, 3, 4), SimpleListener.m_list); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package test.listeners; | ||
|
||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
import org.testng.collections.Lists; | ||
|
||
import test.SimpleBaseTest; | ||
|
||
@Listeners(SimpleListener.class) | ||
public class OrderedListenerSampleTest extends SimpleBaseTest { | ||
|
||
@BeforeClass | ||
public void init() { | ||
SimpleListener.m_list = Lists.newArrayList(); | ||
} | ||
|
||
@BeforeMethod | ||
public void bm() { | ||
SimpleListener.m_list.add(1); | ||
} | ||
|
||
@Test | ||
public void f() { | ||
SimpleListener.m_list.add(2); | ||
} | ||
|
||
@AfterMethod | ||
public void am() { | ||
SimpleListener.m_list.add(4); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.listeners; | ||
|
||
import java.util.List; | ||
|
||
import org.testng.ITestResult; | ||
import org.testng.TestListenerAdapter; | ||
|
||
public class SimpleListener extends TestListenerAdapter { | ||
public static List<Integer> m_list; | ||
|
||
public void onTestSuccess(ITestResult tr) { | ||
SimpleListener.m_list.add(3); | ||
super.onTestSuccess(tr); | ||
} | ||
|
||
} |