JimL
15 years agoContributor
Problems with running testcase via Groovy script
Hi,
I've seen various references to using a controller Groovy script to run test cases, so I've been looking into doing that.
First thing, I've been trying to figure out what to call, and I found this:
http://www.soapui.org/forum/viewtopic.php?t=3688
So, I tried this small Groovy script in a test case, running a test case named "SOAPTestCase":
The SOAPTestCase has two steps:
- A Groovy script to generate some properties that get used in the request, via property expansion
- A request step
Part of what I want to do is to have the controller script (above) fire off (run) a bunch of instances of the SOAPTestCase, and I want the test cases to be run in parallel (threaded). Also, the Groovy test step in that test case generates, among other things a unique id that needs to be used in the request.
I noted that if I set "asynch = false", all of the test cases run, and the unique ids are unique, but if I set "async=true", it appears that all of the test case threads are "sharing" properties, and I end up with the SAME set of properties in all of the test cases run.
I've been searching the Javadocs, and haven't found a good explanation of what that async parameter is suppose to do, but I've been assuming that "asynch=true" means that each test case will be run in its own thread. But, it seems like if I do do "asynch=true", the threaded test cases are sharing the same set of properties.
This seems kind of the opposite of what I found earlier, when I run the test case under a load test. In that case, the test cases get run threaded, but each thread seems to have its own set of properties.
For example, here's what the Groovy log looks like with "async=true":
and here's what it looks like with "async=false":
As you can see from the above, when "async=false", the requests/responses get processed 1-at-a-time (not threaded).
And, when "async=true", the requests get fired off at the beginning, but, the last several "id-..." are all the same (note, the 2nd set of digits in the id is the start time for each request).
The question I have is if I use a Groovy script as a controller, is there a way to have the test cases that are run from the controller script be both threaded AND have their own property set (within a thread)?
Thanks,
Jim
I've seen various references to using a controller Groovy script to run test cases, so I've been looking into doing that.
First thing, I've been trying to figure out what to call, and I found this:
http://www.soapui.org/forum/viewtopic.php?t=3688
So, I tried this small Groovy script in a test case, running a test case named "SOAPTestCase":
def testCase = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite 2").getTestCaseByName("SOAPTestCase")
def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
def async = false
testCase.run (properties, async)
properties = new com.eviware.soapui.support.types.StringToObjectMap ()
testCase.run (properties, async)
properties = new com.eviware.soapui.support.types.StringToObjectMap ()
testCase.run (properties, async)
properties = new com.eviware.soapui.support.types.StringToObjectMap ()
testCase.run (properties, async)
properties = new com.eviware.soapui.support.types.StringToObjectMap ()
testCase.run (properties, async)
The SOAPTestCase has two steps:
- A Groovy script to generate some properties that get used in the request, via property expansion
- A request step
Part of what I want to do is to have the controller script (above) fire off (run) a bunch of instances of the SOAPTestCase, and I want the test cases to be run in parallel (threaded). Also, the Groovy test step in that test case generates, among other things a unique id that needs to be used in the request.
I noted that if I set "asynch = false", all of the test cases run, and the unique ids are unique, but if I set "async=true", it appears that all of the test case threads are "sharing" properties, and I end up with the SAME set of properties in all of the test cases run.
I've been searching the Javadocs, and haven't found a good explanation of what that async parameter is suppose to do, but I've been assuming that "asynch=true" means that each test case will be run in its own thread. But, it seems like if I do do "asynch=true", the threaded test cases are sharing the same set of properties.
This seems kind of the opposite of what I found earlier, when I run the test case under a load test. In that case, the test cases get run threaded, but each thread seems to have its own set of properties.
For example, here's what the Groovy log looks like with "async=true":
Tue Jul 19 22:58:35 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130715617-3-99
Tue Jul 19 22:58:35 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130715705-1-100
Tue Jul 19 22:58:35 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130715707-2-101
Tue Jul 19 22:58:35 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130715709-3-102
Tue Jul 19 22:58:35 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130715710-1-103
Tue Jul 19 22:58:36 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130715710-1-103,1311130715710,1311130716096
Tue Jul 19 22:58:36 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130715710-1-103,1311130715710,1311130716105
Tue Jul 19 22:58:36 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130715710-1-103,1311130715710,1311130716144
Tue Jul 19 22:58:36 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130715710-1-103,1311130715710,1311130716150
Tue Jul 19 22:58:36 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130715710-1-103,1311130715710,1311130716160
and here's what it looks like with "async=false":
Tue Jul 19 22:59:55 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130795861-2-104
Tue Jul 19 22:59:55 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130795861-2-104,1311130795861,1311130795929
Tue Jul 19 22:59:55 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130795930-3-105
Tue Jul 19 22:59:56 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130795930-3-105,1311130795930,1311130796454
Tue Jul 19 22:59:56 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130796455-1-106
Tue Jul 19 22:59:56 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130796455-1-106,1311130796455,1311130796980
Tue Jul 19 22:59:56 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130796981-2-107
Tue Jul 19 22:59:57 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130796981-2-107,1311130796981,1311130797504
Tue Jul 19 22:59:57 EDT 2011:INFO:START-TESTCASE-REQUESTID=id-00000-1311130797505-3-108
Tue Jul 19 22:59:58 EDT 2011:INFO:FINISH-TESTCASE-REQUESTID=id-00000-1311130797505-3-108,1311130797505,1311130798028
As you can see from the above, when "async=false", the requests/responses get processed 1-at-a-time (not threaded).
And, when "async=true", the requests get fired off at the beginning, but, the last several "id-..." are all the same (note, the 2nd set of digits in the id is the start time for each request).
The question I have is if I use a Groovy script as a controller, is there a way to have the test cases that are run from the controller script be both threaded AND have their own property set (within a thread)?
Thanks,
Jim