Forum Discussion

Kenzo's avatar
Kenzo
Occasional Contributor
16 years ago

junit test case in soapUI?

I have this java class which contains a set of junit test cases, each one of them test a web page. I was wondering if it possible to call that class in a groovy test step in soapui, in the same way a ruby program is called.

here is how a ruby program is called in a groovy step in soapui, is there anything similar to this for java programs

java.lang.Runtime a = java.lang.Runtime.getRuntime();
java.lang.Process b = a.exec("ruby C:\\ruby\\my_file.rb");
Thread.sleep(30000);

thx

9 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    Should definitely be possible; package your compiled test(s) in a jar file, put it in the soapui\bin\ext folder which will add it to the classloader of all scripts after restarting soapUI, and then run your tests from ant groovy script using JUnit's runner classes!?

    regards!

    /Ole
    eviware.com
  • Kenzo's avatar
    Kenzo
    Occasional Contributor
    how exactly would I run it using runner classes...I'm  fairly new to soapui, can you give me a sample code

    thx in advance
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    this is JUnit specific knowledge, please check their docs on how to run tests prgrammatically!

    regards,

    /Ole
    eviware.com
  • Kenzo's avatar
    Kenzo
    Occasional Contributor
    Here is my piece of code that I have in a groovy test step:

    import junit.swingui.TestRunner;
    public class Temp {

    public static void main(String[] args){

    TestRunner a = new TestRunner();
    a.run(GoogleTest.class);
    }
    }

    GoogleTest.class contains the set of test cases that I am trying to run in soapUI.
    I tried this in Eclipse and it works fine, but in soapUI  I get the following error:

    org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError: junit.runner.BaseTestRunner.inVAJava()Z

    Don't know how to fix this.

    any ideas?

    thanks
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    hmm.. is this compatible with the bundled JUnit library? Could you try with the junit.textui.TestRunner runner instead?

    regards,

    /Ole
    eviware.com
  • Kenzo's avatar
    Kenzo
    Occasional Contributor
    hi, it works perfectly fine now. thanks
    However, it does not give the result passed/failed, it only tells me if the test finished or not. Should I use some junit class to get passed/failed in soapui?
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    You can fail the groovy script step by throwing an exception from your script (ie if the tests fail)

    regards!

    /Ole
    eviware.com
  • Kenzo's avatar
    Kenzo
    Occasional Contributor
    thanks for all ur help...everything works great
  • mkp's avatar
    mkp
    Occasional Contributor
    The idea you have put forwarded through this thread, calling the class in a groovy test step in soapui, in the same way a ruby program is called, was really great and is definitely possible. It can be done by packaging your compiled tests in a jar file and put it in the soapui\bin\ext folder. Then run the tests using any groovy script using JUnit's runner classes. This will work fine.Its great to know that you have already solved the problem.