By the end of this chapter, we will know how to automate our test setup.
In the past, Karma was used for the automated execution of QUnit and/or OPA tests. As Karma has been deprecated, two alternatives emerged:
Both can be seen as drop-in replacement to Karma, but wdio-qunit-service makes most sense, if WDI5 is already in use. The openui5-sample-app is using the ui5-test-runner, which is why we also use it here. Luckily, there is not much configuration to do - we only have to install the package and add a script to our package.json file.
➡️ Run the following command from the codejam.supermarket/uimodule/ directory:
# make sure you are in the uimodule/ directory
npm install ui5-test-runner -D➡️ Add the following code to the scripts section of the codejam.supermarket/uimodule/package.json file:
,
"test-runner": "ui5-test-runner --url http://localhost:4004/uimodule/test/testsuite.qunit.html --report-dir webapp/report"To start the ui5-test-runner, we need to start the project as usual from the project root, including the backend server.
➡️ Run the following command from the codejam.supermarket/ directory:
# make sure you are in the codejam.supermarket/ directory (project root)
npm run dev:server➡️ Open a new terminal (don't reuse the other one!) and run the following command from the codejam.supermarket/uimodule/ directory to start the tests:
# make sure you are in the uimodule/ directory
npm run test-runnerYou'll notice how the tests are being executed headless. Feel free to inspect the test results at http://localhost:4004/uimodule/report/report.html.
As we are using the ui5-test-runner, code coverage can also be supported for testing. There's a quite good documentation available about enabling coverage reporting.
➡️ Just check out the following page: https://github.com/ArnaudBuchholz/ui5-test-runner/blob/main/docs/coverage.md.
Continue to Chapter 09 - Deployment
