Overview
Dana comes with some tools to help you to test your application and of course the framework itself.
There are three types of tests:
- unitary tests: test in an isolated way a single class or piece of code in order to check its good implementation and behaviour
- functional/spec tests: test a feature which concerns several components and their interactions in order to check functional parts of the application
- integration tests: test in a “production” (like) environment, with the right implementations, on a real devices and backend’s
They come with code coverage analysis, so you know exactly the code sections not covered by the tests.
Unitary test
Unitary test are located inside tests/unit
directory.
Unitary tests results & coverage reports are generated into doc/reports/unit
.
A typical unitary test should look like the following:
describe("AppTheme", function () {
let AppTheme,
appTheme;
/**
* Load the Classes needed for the tests, initialize global variables
*/
before(function () {
return $UnitTest.getClass("@AppTheme").then(function (loadedClasses) {
AppTheme = loadedClasses.class;
});
});
/**
* Destroy the Class(es), cleanup
*/
after(function () {
return $UnitTest.destroyClass(AppTheme);
});
/**
* Before each test, create a fresh instance of AppTheme
*/
beforeEach(function () {
appTheme = new AppTheme();
});
it("should have created an instance of 'AppTheme'", function () {
expect(appTheme).to.exist;
expect(appTheme).to.be.an.instanceof(AppTheme);
});
});
Unitary test uses Mocha test framework.
Functional tests (specs)
Functional tests are located inside tests/automation
directory.
Functional tests results & coverage reports are generated into doc/reports/cucumber
.
A typical spec test should look like the following:
Feature: Go back to home
Go back to home from different screen.
# We can comments scenario/steps with '#' char
Scenario: Back to home from Fip
Given i start on "fip" screen
When i press "home"
Then "home" screen is displayed
And "rail" item 0 is focused
Scenario: Back to home from Live Player
Given i start on "live player" screen
When i press "home"
Then "home" screen is displayed
And "rail" item 0 is focused
Spec tests are written with Gherkin.
Integration tests
Integration tests are used to check that components implementation works on specific device for a specific vendor.
It means that these tests will not use mocked components anymore but directly the ones which are supposed to exist on the vendor specific device.
It means also that a vendor has to describe a default device configuration to be able to run those tests.
Dana does not have embedded tools to support integration tests.
Run tests
To run tests, use the following command
npm run test:cucumber
npm run test:unit
Continuous integration
When you run the tests, xml report file is created under doc/reports/**/junit
.
You must configure your CI tool to read those files.