Forum Discussion

oleksii's avatar
oleksii
Occasional Contributor
8 years ago

TestSuite teardown script is not executed when LoadTest is run?

I have a testsuite which contains a bunch of load tests. There is a teardown script which is setup in test suite and I expected that it would run after all load tests finish, but it did not happen.

Load test is run with shell command similar to this one:

%SOAPUI_HOME%\bin\loadtestrunner.bat -r -fc:\Programs\SmartBear\SoapUI-5.2.1\loadteststatistics -s "ReadOnlyScenarios" -Doracle.jdbc.timezoneAsRegion=false -Gsoapui.properties=c:\GitRepository\CIP\cip.dev.properties CIP-SmokeTests-Load-v2.xml

 

Is it designed in such way or I'm missing something? I can think of only one workaround: create a new test case in the end with a groovy step, add load test for it which executes the step only once.

8 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    I think in the case you're describing, since load tests are defined at TestCase level, I have always used the Setup/Tear down script tabs from within the load test to run scripts - would this work for you?

     

    Regards,

    Rupert

  • oleksii's avatar
    oleksii
    Occasional Contributor

    Unfortunately, this will not work for me: in my teardown script I process statistics file created and it seems like the files are not created yet or they are empty when the loadtest teardown script is executed.

     

    I think it may be due to loadtestrunner context? I mean that the script may run OK from GUI, but fail coz context is different during shell execution via loadtestrunner. The second string in code may not work and list of test cases is not created.

     

     

    log.info "runnning teardown script"
    def testCases = testSuite.getTestCaseList();
    for (testCase in testCases) {
    	def statisticsPath = "c:\\Programs\\SmartBear\\SoapUI-5.2.1\\loadteststatistics\\"
    	def testCaseName = testCase.name
    	def testCaseReportFile = new File("${statisticsPath}${testCaseName}.csv")
    	def testCaseResultFile = new File("${statisticsPath}${testCaseName}.log")
    
    	if (testCaseResultFile.exists()) {
    		testCaseResultFile.withReader {reader -> testCaseReportFile.append(reader.readLine() + '\n')}
    		//testCaseResultFile.withInputStream {input -> testCaseReportFile << input}
    	}
    }

     

    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      Hi,

       

      Ok, since the load test setup script runs at TestCase level rather than TestSuite (which can have multiple TestCases), how about if you modify the script to work for just the TestCase that the load test is for e.g. something like:

       

      og.info "runnning teardown script"
      
      def statisticsPath = "c:\\Programs\\SmartBear\\SoapUI-5.2.1\\loadteststatistics\\"
      	def testCaseName = loadTestRunner.loadTest.testCase.name
      	def testCaseReportFile = new File("${statisticsPath}${testCaseName}.csv")
      	def testCaseResultFile = new File("${statisticsPath}${testCaseName}.log")
      
      	if (testCaseResultFile.exists()) {
      		testCaseResultFile.withReader {reader -> testCaseReportFile.append(reader.readLine() + '\n')}
      		//testCaseResultFile.withInputStream {input -> testCaseReportFile << input}
      	}
      

      Sorry, if I've missed something and I haven't tested this code, just thought you could get the TestCase name instead using loadTestRunner.loadTest.testCase.name

       

      Regards,

      Rup

  • oleksii's avatar
    oleksii
    Occasional Contributor

    I changed test suite teardown script to this:

    	def statisticsPath = "c:\\Programs\\SmartBear\\SoapUI-5.2.1\\loadteststatistics\\temp.txt"
    	def testCaseReportFile = new File("c:\\Programs\\SmartBear\\SoapUI-5.2.1\\loadteststatistics\\temp.txt")
    	testCaseReportFile.append("some text")

    And the file was not created after running loadtestrunner from console which proves that this test suite teardown script is not called when load tests are run - what a pitty.

    The file was created when I run this script in GUI which confirms that the script is OK.

     

    I will continue by adding extra load test in the end of my test suite which will execute the script.

  • oleksii's avatar
    oleksii
    Occasional Contributor

    Not Load Test teardown/setup tabs, but Test Suite teardown (not sure about setup) tab for Load testing.

    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      Ok, I think you are saying that the TestSuite setup/tear down isn't running in the context of a load test - it wont, as we discussed. I was just asking whether you can move your TestSuite's setup/tear down scripts into the load test's setup/teardown scripts instead.