Tutorial: Record & Generate
The easiest way to create a test case:
- Mark the service for recording and optionally define sub-services for stubbing
- Run the service with different inputs, e.g. from Designer or in a QA environment
- Generate a test suite service
- Optionally provide meaningful test case names
The IwTestSamples package contains services and test suites for you to inspect. We'll create a test suite for:
- iw.test.samples.tutorial:main
This is a simple flow service that takes a three digit random number as an input and has this behaviour:
- If the number starts with '5' then it throws an exception.
- Else it calls iw.test.samples.tutorial:color twice:
- Once with the second digit
- Once with the third digit
- iw.test.samples.tutorial:color returns a different color if the digit is 1..9. For any other character it throws an exception.
- The output is 'color1' and 'color2'
Try it out:
Service | Expected result |
---|---|
iw.test.samples.tutorial:main?random=345 | color1: purple; color2: green |
iw.test.samples.tutorial:main?random=512 | Flow Exception: Range 5xx: Unsupported (512) |
iw.test.samples.tutorial:main?random=407 | Flow Exception: Unrecognized color: 0 |
The wrapper service iw.test.samples.tutorial:random generates a random three-digit number and then calls iw.test.samples.tutorial:main. Try it: random colors
In this tutorial we'll record test cases for iw.test.samples.tutorial:main and we'll record stubs for iw.test.samples.tutorial:color. Note that errors will also be recorded and be part of the test case.
Instructions
- Schedule iw.test.samples.tutorial:random to run every 4 seconds by executing the service iw.test.samples.tutorial.admin:start either in Designer or by clicking this link: start
- Go the record page and start the recording facility (if it's not already started) by clicking the arrow next to '(local)'.
- Then click and start typing 'main'. In the panel that appears below double-click on iw.test.samples.tutorial:main.
-
Select iw.test.samples.tutorial:color as a 'service to stub'. Your screen now looks like this:
Search ServiceRemote server:(local)Package (optional):Service:Select services to stub (optional):pub.string:replace
iw.test.samples.tutorial:color
Click 'Start recording'. Your screen should look like this:
Recorded service runs on '(local)'. iw.test.samples.tutorial:main - iw.test.samples.tutorial:color
IwTestSamples 0 - You'll see the test run counter increment every four seconds. You can click on the link to see what's been recorded so-far. Click the blinking square to stop the recording.
- Generate a test suite by clicking
- You're presented with a dialog that let's you control the:
- Target package
- Test Suite name
- Test Suite service name
- In the test suites page you'll see the newly created test suite. Click the pencil icon next to it and give the test case meaningful names. This is important, as they'll appear once you execute the test suite.
- Stop the automatic execution of iw.test.samples.tutorial:random by executing the service iw.test.samples.tutorial.admin:stop by clicking this link: stop
- Click the run icon to execute the whole test suite or just selected test cases. The results are visible in the results page.
The result of this is:
- A new flow service named iw_tes.test.samples.tutorial:main_ts in the package IwTestSample_Test. If the package didn't exist before, it does now.
- The recorded data was copied to the '[generate.test.package.folder]' in the (new) test package and was deleted from the temporary location (see '[record.storage.location]' in the configuration page).
Notice the call to iw.text.execution.pub:execute and inspect the inputs. The only thing left to do for you is give the test cases meaningful names.
You can directly execute this flow service. It will execute the four test cases and the result are available in the Results page.