Forum Discussion

zen_paul's avatar
zen_paul
Occasional Contributor
8 years ago
Solved

how can I invalidate a test, if the data is not found on a database.

As can be seen I am new to SoapUI, so I suspect this will have been answered before, but I haven't found it yet. For our tests we select test items from a database, and then run the test using that item. If the item is not found, we do not want to run the test, but want to 'invalidate' the test, rather than fail the test. This will allow us to more easily identify real failures, and provide a list of tests that are not being run, because we don't have the test data available. 

 

Is this function available in SoapUI Pro out of the box?

Can this be done using Groovy scripts, and has anyone done this sort of thing that can help with examples of Groovy scripts doing this. We are also new to Groovy and will only used it for SoapUI tests and have only created a couple of scripts so far to do some assertions. 

5 Replies

    • zen_paul's avatar
      zen_paul
      Occasional Contributor

      Yes, this looks like the thing to do ...

      I have added a test step to the test case and got details out to the script log and it all looks OK 

       

       

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
      log.info('my log here')
      log.info('Just wanted to cancel this test ' + context.getCurrentStep().getLabel())

      testRunner.cancel('Just wanted to cancel this test ' + context.getCurrentStep().getLabel())

       

      In the test case log I get .... 

      • Test started at 2016-09-27 15:50:08.106
      • Step 1 [GAD.001: Overall status 1] OK: took 2074 ms
      • TestCase canceled [Just wanted to cancel this test GAD.001-Cancel-Test], time taken = 2096
      • Step 2 [GAD.001-Cancel-Test] CANCELED: took 22 ms

      But I get this in the error log, I have no idea why this is happening, I don't have any assertions on the results from the groovy script, it just stops the test as Canceled.

       

      Any help on how I should be getting rid of this error, if the groovy script is disabled, then the test passes its step1...

       

      • Tue Sep 27 15:50:10 BST 2016:ERROR:groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.getAssertionList() is applicable for argument types: () values: []
      • groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.getAssertionList() is applicable for argument types: () values: []
      • at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
      • at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
      • at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
      • at Script1$_run_closure1.doCall(Script1.groovy:3)
      • at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      • at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      • at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      • at java.lang.reflect.Method.invoke(Unknown Source)
      • at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      • at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      • at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      • at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      • at groovy.lang.Closure.call(Closure.java:411)
      • at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3873)
      • Radford's avatar
        Radford
        Super Contributor

        My guess is that a later script in your test case (likely a teardown script) is iterating through the test steps and getting the assertion lists for each step, possibly to check for and report failures?

         

        Not all test steps implement the Assertable interface (this specifies the getAssertionList() method, for example the Groovy Script test step does not.

         

        You should find where you are calling the getAssertionList() method and add a check to see if the "current" test step is assertable before calling getAssertionList(), the following is an example Test Case teardown script that should get you started, it uses the Membership operator to check if a class implements an interface:

         

        // Loop through each test step in test case
        // NOTE: getTestSteps() returns a Map with the step name as the key and the actual step as the value 
        testCase.getTestSteps().each() { testStepName, testStep  ->
         // Check to see if current step implements the interface Assertable
         if (testStep in com.eviware.soapui.model.testsuite.Assertable){ 
          log.info 'The test step "' + testStep.getName() + '" implements the Assertable interface.'
         }
        }