7. Testing - DIT113-V22/group-01 GitHub Wiki

Testing

What we test

  • For sprint 1 the goal is to test the connection to the car over mqtt.
  • In sprint 2 we will add tests for the quiz logic.

How we add tests for the car connection

You can follow the ToDos inside the code, which basically boils down to the following:

  1. Add observable fields for the sensors data. MqttCar.java
  2. Next, make sure to subscribe the corresponding topic and update the observable field when a message is received on that topic. MqttCar.java
  3. If applicable add methods for publishing data / sending commands to the car. MqttCar.java
  4. Lastly, add some tests in the Given-When-Then format. MqttCarTest.java

How to run the car connection tests manually

  1. Start a mqtt broker (mosquitto).
  2. Compile and start the car code inside the emulator.
  3. Run the test file.
  4. After each test, reset the cars position.

Why the car connection tests are instrumented tests

The mqtt library we use requires a context to work. Simple unit tests don't have access to this, thus we use an instrumented test which has. Furthermore, the car connection tests aren't really unit tests in a strict sense but integration tests. To still be able to test it we use our created simple integration test utils which provide functions for delayed responses and less accurate results.

Why the car connection tests aren't run automated inside a GitHub action

To test the car connection, we need a car which responds to the mqtt messages. Running the arduino code in an emulator for a GitHub action is simply not feasible for this project and its scope.