forked from NASAWorldWind/WebWorldWind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HowToCreateAndRunUnitTests.txt
91 lines (65 loc) · 3.16 KB
/
HowToCreateAndRunUnitTests.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Preparation: Install Karma and Jasmine
======================================
If you don't have Node.js, please visit https://nodejs.org/en/download/ and
install the appropriate release for your system.
In a terminal, go to the project folder and run “npm install” to install
the necessary dependencies saved as devDependencies in 'package.json' file.
How to Run the Tests
====================
Continuous Testing from the Terminal
------------------------------------
In a terminal, go to the project folder and run “karma start karma.conf.js”.
This will start a process, which automatically runs all tests when source
files are changed and saved as long as the process is running.
Testing from WebStorm
---------------------
If you use the workspace configuration provided in the source code repository,
you already have a run configuration called "Karma Tests".
Otherwise, running karma.conf.js in WebStorm will run the tests only once
unless the re-run option is selected. In this case, all tests are run when
source files are changed similarly to starting Karma from the terminal.
The above-mentioned run configuration can also be created manually with the
following steps:
- Go to Run -> Edit Configurations...
- Click on the '+' button on the top left side (Add New Configuration)
- Select 'Karma' from the menu
- In Configuration file box insert the path of the file 'karma.conf.js'
- In Name box insert the name of the configuration (e.g. Karma Tests)
- Save the configuration
Testing with Other Browsers
---------------------------
By default, the tests run in PhamtomJS. They can be run in other browsers by
changing the list of browsers in karma.conf.js to, for example:
browsers: ['PhantomJS', 'Chrome’]
Please make sure that you also have the approriate launchers available in your
node modules, for example:
npm install karma-chrome-launcher
Integration with the Build Process
----------------------------------
The tests are automatically run when the project is built using the Grunt.
Test Results
------------
The test results are available in "test/<USED_BROWSER>/test-results.xml".
How to Create a Test
====================
Please have a look at the existing tests for reference.
1) Go to the 'test' folder and create a new file. Note that the 'test' folder
should maintain the same structure as the 'src' folder, so if the module to
be tested is located in 'src/features/', the related test should be in
'test/features'.
2) Save the file as '<name of the module to be tested>.test.js'
3) The basic structure of the test is the following:
define([ <list of paths of the modules that this module depends on> ],
function (< list of parameters>) {
"use strict";
describe("<Name of the module to be tested to help you understand what the test is supposed to be>",
function() {
....
it("<Description of the expected results of the test, usually it starts with the word 'should'>",
function() {
expect( ... ).<matcher>(...);
})
});
});
For more information about the Jasmine Framework used for defining the tests,
please visit: https://jasmine.github.io/2.0/introduction.html