Forum Discussion

tdrury's avatar
tdrury
Contributor
11 years ago

Run TestCase from Java and set Settings?

I have some experience writing Java which calls soapUI - we've written our own maven plugin which executes multiple projects, but...

I need to be able to run a single TestCase, be able to search the resulting context for some parameters, but also be able to set preemptive authentication. How can I do this?

The "Integrating with JUnit" section of the online help seems ideal for running a single TestCase and getting the resulting context, but I don't see how I can set soapUI Settings at that level - is there another way of setting preemptive authentication?

When I run from the SoapUITestCaseRunner level, I can set the settings easily, but I don't see how I can get access to the TestCase's context after it has run.

Help!
-tim

9 Replies

  • Hello Tim,

    I read your earlier post suggesting that you had got this running via some Java Scripting? Are you still having issues? Another thing that you should keep in mind is that groovy scripting is integrated into SoapUI as well and it is better integrated with the tool.

    Regards,
    Temil
  • Right, but what I'm attempting to do is run a SoapUI test case from a junit/testng integration test, so I need to be able to call SoapUI classes from within my Java test code. That's easy enough, but my requirements are particular:

    1. I need to be able to run the SoapUI test runner with specific SoapUI settings - namely, preemptive authentication needs to be true.
    2. I need access to the run context of the test case after it has finished so I can fetch some properties that were set within the SoapUI test case and use them in my junit/testng integration test.

    The way the SoapUI code was written, those two requirements seem to be at odds with each other. You can either run a single TestCase and have access to the context, but not be able to set settings, or you can run a test case via the SoapUITestCaseRunner and set settings, but not have access to the finished TestCase context.

    I was able to use this method:

    WsdlProject project = new WsdlProject( "src/dist/sample-soapui-project.xml" );
    TestSuite testSuite = project.getTestSuiteByName( "Test Suite" );
    TestCase testCase = testSuite.getTestCaseByName( "Test Conversions" );
    TestRunner runner = testCase.run( new PropertiesMap(), false );

    which is from the online help. I can get the TestCase runtime context via this method, but I found no way to set SoapUI settings via these classes. So I wrote my own SoapUI test runner class which does the above but also instantiates the SoapUIPro.SoapUIProCore class within the constructor of my SoapUI test runner class. (I think the same would work for the non-Pro version using SoapUI.SoapUICore class.)

    So, effectively, I did this:

    SoapUIPro.SoapUIProCore soapuiCore = new SoapUIPro.SoapUIProCore(true, "/path/to/soapui-settings.xml");
    WsdlProject project = new WsdlProject( "src/dist/sample-soapui-project.xml" );
    TestSuite testSuite = project.getTestSuiteByName( "Test Suite" );
    TestCase testCase = testSuite.getTestCaseByName( "Test Conversions" );
    TestRunner runner = testCase.run( new PropertiesMap(), false );

    This just seems really "hacky" and was unsure if it would cause other unintended consequences, which is why I was hoping for some feedback from SmartBear.

    -tim
    • These replies have been moved.
    • VernonCrabtree's avatar
      VernonCrabtree
      Occasional Contributor

      Tim,

      I too am trying to call SoapUI from Java, wanting to run certain test cases with certain properties and then be able to determine what failed where (get a report).

      I see that you have followed a similar path to me (based on the examples from https://support.smartbear.com/readyapi/docs/testing/integrations/junit.html) - I have a couple of questions:

       

      1) Did you ever get a satisfactory answer from Smartbear?

       

      2) Where do I import SoapUIPro.SoapUIProCore from?  Or has this disappeared from recent versions?

       

       

      • groovyguy's avatar
        groovyguy
        Champion Level 1

        You are replying to a post that is almost 4 years old. You may want to start a new post for your problem. 

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    1. I need to be able to run the SoapUI test runner with specific SoapUI settings - namely, preemptive authentication needs to be true.
    >> For this one I would suggest write a groovy script to set the SoapUI settings and have it on your project load script. So, this script will be called every time your project is loaded. You can have a look at for more hint http://www.soapui.org/Working-with-Projects/working-with-soapui-projects.html#2-the-project-window-and-overview and http://www.soapui.org/Scripting-Properties/tips-a-tricks.html#1-2-get-and-set-settings

    2. I need access to the run context of the test case after it has finished so I can fetch some properties that were set within the SoapUI test case and use them in my junit/testng integration test.
    >> Can you use project level properties to store those values and later access them from the project itself? See http://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/WsdlProject.html for example.

    Regards,
    Shadid
    SmartBear Sweden.
    • tania29's avatar
      tania29
      New Member

      Hi,

       

      TestCaseRunner runner = (TestCaseRunner) test.run(null, false); 

       

      i am getting java.net.unknownhostexception after running the above code.

       

      Can you please tell me the solution?

      • nmrao's avatar
        nmrao
        Champion Level 3
        tania29,
        Suggest you not to cross post. Please create a new topic with as much details as possible to your issue.