docs

Step 1: Overview and Testing Strategy

In this step, we will take a look at the prototype and define the test strategy for our app. The prototype already contains the infrastructure for unit and integration testing and a minimum set of tests and features.

Note:

In this tutorial we will focus on writing clean unit and integration tests for apps. They build the foundation and are crucial for good application quality. We will also outline how to write testable code. Not all implementation patterns can be tested easily, but when writing the test code together with the implementation code as we have in this tutorial, testable code is a natural result.


Preview

The prototype app


Coding

  1. To set up your project for this tutorial, download the files at Testing - Step 1.

  2. Extract the downloaded .zip file at the desired location on your local machine.
  3. Open a shell in the extracted folder and execute npm install.
  4. Execute npm start to start the web server.

After downloading Step 1, you should have the following files:

Folder structure with downloaded files


The Initial App

With the downloaded code, you now have the bulletin board prototype, set up according to the OpenUI5 best practices. The prototype provides the common features of an OpenUI5 app. If you have completed the Walkthrough tutorial, you should be familiar with most of the source code in this step. Additional features of the app are:

Now that we have a running prototype, we can further extend it with additional tests and features. Make sure that the app is running by calling the test page and the test suite from the entry page webapp/test.html. The app should display a list of bulletin board posts as seen in the screenshot above and the tests should run without errors.


Test Strategy

Let’s first take a look at best practices for testing apps written in OpenUI5. JavaScript is a dynamic programming language and only some issues can be detected by static code check tools and manual testing. Automated tests that execute the code regularly are beneficial for good quality and development productivity – especially when you’re developing in short development cycles.

We expect our prototype to be released and shipped as a product soon, so we need a solid testing strategy. Fortunately the prototype team has already thought ahead and prepared an infrastructure for unit and integration testing that is included in the app. This is a really good starting point for further enhancements of the app.

The mock server is also set up and allows us to test the app with local test data instead of a real back-end service. We can use the mock data for writing reliable integration tests that do not depend on another system which might be unavailable when the tests are run.

Note:

If you start developing an app from scratch, you should always consider testing from the very beginning of the software life cycle. Nobody wants to write tests for undocumented code and make assumptions about the logic. It is worth the effort to think about code checks, unit and integration testing, and a solid testing strategy from the very start.

Before you start implementing your first test, you should think about how to test the different aspects of your application. The image below shows the testing tools along the agile testing pyramid.

Testing pyramid

When you set up application testing, you should automate as many testing steps as possible. If you immediately write a test for all the features that we implement, then you can greatly reduce manual testing efforts that are time consuming and cumbersome. If you change something later, you can simply run the existing tests and see if the functionality is still working as expected.

OpenUI5 comes with two testing tools: QUnit for unit testing and OPA5 for integration testing. The unit tests are the foundation of our testing pyramid and they should validate the most important logic of our app. In addition, you can write integration tests for more interaction-related functionality, such as interacting with UI elements of the app.

There might still be features that are hard to test with these client-side testing frameworks. Certain features might require a more sophisticated system test, such as a screenshot comparison that can be implemented with additional testing frameworks. And of course, you should also schedule manual tests (for example, browser, performance, or security tests) to make sure that the app is behaving as expected.


Conventions

Parent topic:Testing Tutorial

Previous:Step 2: A First Unit Test

Related Information

Testing

Unit Testing with QUnit

Integration Testing with One Page Acceptance Tests (OPA5)

Mock Server

Walkthrough Tutorial (JavaScript)