Forum Discussion

Jonathan_Easter's avatar
Jonathan_Easter
New Contributor
16 years ago

Help needed to start two Mock Services before a jUnit test

Hello,
  I am attempting to set up a SoapUI + Maven + Surefire (to run jUnit test) to automate my test/build step. I would like to in the test phase of the build first fire up two soapUI mock services, then fire the jUnit tests. But so far I am having limited/no luck getting everything tied together. I have the Mock Services defined, I have maven running my jUnit tests, but I am missing the final part. I have had limited success just executing the main of soapUI but there must be a better way. Any tips/suggestions/snippets etc would be much appreciated.  I'm at the point of not even knowing the proper questions to ask.

5 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    hmm... since the maven plugin currently only allows you to start one mockservice maybe you could create a testcase that
    - starts the mockservices in its startup script
    - saves the created mockrunners to the context
    - contains a delay step
    - and a groovy step that checks if the tests have finished (based on some criteria) and either loops back to the delay or ends the test
    - stops the mockrunners in its teardown script

    sound workable?

    regards!

    /Ole
  • ... not quite as clean as I would hope...  Would Ideally like for something like Maven:
    1. check see if services are running
    2. if not start each sending reports as well...
    3. then run the jUnit tests.. reports back
    4. tear everything down.

    Right now w/ the plugin I really don't see a way to get to that level... or even a way to start two of them from command line...

    Would it be possible to start the mock services directly via java?
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    sure, you could start them via the soapUI API;

    WsdlProject project = new WsdlProject( "pathtoprojectfile" );

    WsdlMockService mockService1 = project.getMockServiceByName( "..." );
    WsdlMockRunner mockRunner1 = mockService1.start();

    WsdlMockService mockService2 = project.getMockServiceByName( "..." );
    WsdlMockRunner mockRunner2 = mockService2.start();

    now run your tests.. and then stop them with

    mockRunner1.stop();
    mockRunner2.stop();

    (Hope I got that right :-)

    regards!

    /Ole
    eviware.com
  • Cool...
    That seemed to work, What Jar files would I need to include into the project itself, I just threw everything from the /lib and the soapui.jar file into the project but that seems like swatting flies with a baseball bat. I see that the API's have methods for checking etc if services are running.

    Would this be something that could be added to the maven plugin?