Created
December 3, 2016 14:19
IExecutionListener
This file contains hidden or 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
// ExecutionListener1 | |
package com.Iexecutelistener; | |
import org.testng.IExecutionListener; | |
public class ExecutionListener1 implements IExecutionListener { | |
private long startTime; | |
@Override | |
public void onExecutionStart() { | |
startTime = System.currentTimeMillis(); | |
System.out.println("Starting On execution test from ExecutionListener1 "); | |
} | |
@Override | |
public void onExecutionFinish() { | |
System.out.println("Starting On execution test has finished, took around " + (System.currentTimeMillis() - startTime) + "ms"); | |
} | |
} |
This file contains hidden or 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
// ExecutionListener2 | |
package com.Iexecutelistener; | |
import org.testng.IExecutionListener; | |
public class ExecutionListener2 implements IExecutionListener { | |
@Override | |
public void onExecutionStart() { | |
System.out.println("Starting On execution test from ExecutionListener2"); | |
} | |
@Override | |
public void onExecutionFinish() { | |
System.out.println("Starting On execution test TestNG is finished"); | |
} | |
} |
This file contains hidden or 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
Create a testNG test class TestClass, it has a @BeforeSuite, a test and an @AfterSuite method. | |
package com.Iexecutelistener; | |
import org.testng.annotations.BeforeSuite; | |
import org.testng.annotations.Test; | |
public class TestClass { | |
@BeforeSuite | |
public void beforeSuite() { | |
System.out.println("Am in Before Suite"); | |
} | |
@Test | |
public void t() { | |
System.out.println("In Test Method t..."); | |
} | |
} | |
This file contains hidden or 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
Create XML file that calls these listeners like; | |
<?xml version="1.0" encoding="UTF-8"?> | |
<suite name="Suite" parallel="false"> | |
<listeners> | |
<listener class-name="com.Iexecutelistener.ExecutionListener1" /> | |
<listener class-name="com.Iexecutelistener.ExecutionListener2" /> | |
</listeners> | |
<test name="Test"> | |
<classes> | |
<class name="com.Iexecutelistener.TestClass" /> | |
</classes> | |
</test> | |
</suite> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment