Forum Discussion

BA_Service_Haus's avatar
BA_Service_Haus
Regular Contributor
13 years ago

How to run Mocks as a service?

Hi,

we offer a keyworddriven framework to our testers for running soapUI testcases.
Thus all testcases are executet via command line.

Now we want to enable the user to start and stop a mock via keywords.
Therefor we thought about the following approach:
- Creating 2 special testcases: one of them starting the mock and the other stopping it (via groovy script teststep)

So if the user wants to start the mock, the framework will run the corresponding testcase.
But after this, the user wants to run another (this time a real) testcase, that uses the mock. If this is done, the testcase fails.

I assume that the mock, started with the first testcase, is stopped after the testcase execution via command line was finished, isn't it?
So is there a possibility to run the mock as a service this way?

Please notice, that it is no option for us to run the mock via commandline directly (using mockServicerunner.bat) as this requires control of the DOS-window (mock only stops after pressing a key here).

Best regards
Nico

5 Replies

  • Hi Nico,

    I'm not sure I understand - if you start a MockService from a groovy script it will stop first when you either stop it again or exit soapUI (or the command-line runner); it won't stop automatically when the TestCase that contained the script ends. Couldn't your keyword driven approach (interesting!) run this TestCase first, then run the others that are dependent on the Mock (all in the same testrunner execution) ?

    regards!

    /Ole
    SmartBear Software
  • BA_Service_Haus's avatar
    BA_Service_Haus
    Regular Contributor
    Hi Ole.

    thanks for your reply.

    For a better understanding, please let me explain our approach:
    - the tester defines the request and assertion data for one service operation by using keywords.
    - the kdt(keyword driven test)-Framework writes them down to a testcase within a soapUI project file
    - with another keyword this soapUI testcase can be executed (this is done by calling the testrunner.bat for the prepared testcase)
    - if the user wants to test another operation within the same kdt, he just repeats the same steps

    You can see, we call the testrunner.bat for a single testcase which always contains just a single operation request.
    Now we want enable the user to define a required mock, by using keywords.
    But I don't know how to start the mock the best way.
    One idea currently is to define the start and stop of the mock within the setup and tear down script (this can be done by the framework too).
    But if there is an "intelligent" mock (e.g. a stateful one), than it might be necessary to run the mock from the start and not stop it until the whole kdt was finished.

    If you have another (better) idea, I would be glad to hear it.

    Best regards
    Nico
  • Hi Nico,

    Thanks for clarifying. Hm...

    For mocks that need to "live" only during the execution of the single TestCase I suggest you use an external TestRunListener that implements the beforeRun / afterRun events to start/stop the Mock (see http://soapui.org/Developers-Corner/ext ... -in-soapui) - you could set a TestCase property in the project file when creating the test to indicate to the listener which Mock to run (if there are several in the project).

    If your Mock needs to live for longer than a single TestCase I'm not sure - perhaps you could use the toolrunner to generate a war from your Mock and deploy that automatically to a local Tomcat!? All this would have to be done from the kdt-framework I guess.. alternatively the framework could simple start the MockService itself by directly loading the project and invoking the corresponding APIs (if it is written in Java...)

    Does that give you any ideas?

    regards!

    /Ole
    SmartBear Software
  • BA_Service_Haus's avatar
    BA_Service_Haus
    Regular Contributor
    Hi Ole,

    thanks for the (very) quick reply.

    We could run the mocks on an WebLogicServer. But in the past we had some problems doing this (maybe this is another topic).

    Thanks for your help.

    Best regards
    Nico
  • Hi Nico,

    yes - I remember those issues - but I also thought they got resolved at some point!? Well, if you decide to try that and still have issues please let us know!

    regards,

    /Ole
    SmartBear Software