TraceyK
13 years agoOccasional Contributor
TestRunListener.beforeRun and JUnit
Hi,
I have integrated my soapUI Pro 4.5.1 tests into JUnit by writing a JUnit wrapper for each soapUI test.
Here is an example of a wrapper.
public class PMGetsOsExecAndRepliesSuccessTest {
test
public void PMGetsOsExecAndRepliesSuccessTest() throws Exception {
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile("REST-test-soapui-project.xml");
runner.setTestSuite("Phoenix REST API Test Suite");
runner.setTestCase("PM gets OsExec and logs success for cmdId");
runner.run();
}
}
In soapUI I've set up an event listener for TestRunListener.beforeRun. It has a Groovy script that sets an environment variable with the endpoint for the tests to use.
When I run the JUnit tests (I'm using Ant) the event listener is not getting triggered and the wrong endpoint is used. When I use TestRunner within soapUI the event listener is triggered as expected.
My question is, should the event listener get triggered when I run the test from JUnit and Ant? Or do the event listeners only work when the soapUI tests are run when the TestRunner is started from within soapUI?
I'd like to get the above solution to work if possible since I already have a dozen or so tests written but if it doesn't work my other option is to use Ant to start the soapUI tests by command line.
I appreciate the help/advice.
I have integrated my soapUI Pro 4.5.1 tests into JUnit by writing a JUnit wrapper for each soapUI test.
Here is an example of a wrapper.
public class PMGetsOsExecAndRepliesSuccessTest {
test
public void PMGetsOsExecAndRepliesSuccessTest() throws Exception {
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile("REST-test-soapui-project.xml");
runner.setTestSuite("Phoenix REST API Test Suite");
runner.setTestCase("PM gets OsExec and logs success for cmdId");
runner.run();
}
}
In soapUI I've set up an event listener for TestRunListener.beforeRun. It has a Groovy script that sets an environment variable with the endpoint for the tests to use.
When I run the JUnit tests (I'm using Ant) the event listener is not getting triggered and the wrong endpoint is used. When I use TestRunner within soapUI the event listener is triggered as expected.
My question is, should the event listener get triggered when I run the test from JUnit and Ant? Or do the event listeners only work when the soapUI tests are run when the TestRunner is started from within soapUI?
I'd like to get the above solution to work if possible since I already have a dozen or so tests written but if it doesn't work my other option is to use Ant to start the soapUI tests by command line.
I appreciate the help/advice.