UNPKG

5.61 kBMarkdownView Raw
1## Test Modes
2
3Tests can be executed in three different modes as follows:
4For Windows use **set** and for OSX, Linux use **export**
5* **LIVE**
6Tests will be run against the Live Service, no recording happens
7To run the tests in **LIVE** mode, set the following environment variable:
8```
9set NOCK_OFF=true
10```
11
12* **RECORD**
13Tests will be run against the Live Service and the HTTP traffic will be recorded to a file at "azure-xplat-cli/tests/recordings/{test-suite}/{full-test-title}.nock.js"
14To run the tests in **RECORD** mode, set the following environment variable:
15```
16set NOCK_OFF=
17set AZURE_NOCK_RECORD=true
18```
19
20* **PLAYBACK**
21Tests will run against the previously recorded HTTP traffic, vs a Live Service. The Travis CI runs tests in this mode.
22To run tests in **PLAYBACK** mode, unset the following environment variables:
23```
24set NOCK_OFF=
25set AZURE_NOCK_RECORD=
26```
27The recordings will get saved in azure-xplat-cli/test/recordings/{test-suite} directory
28
29## Partial recordings
30
31#### Recording tests related to a specific service/feature
32If you plan on adding some tests / features and do not need to regenerate the full set of test recordings, you can open the file:
33```
34tests/testlist.txt (if you are writing tests for commands in asm mode)
35tests/testlistarm.txt (if you are writing tests for commands in arm mode)
36```
37and comment out the tests you do not wish to run during the recording process.
38
39To do so, use a leading \# character. i.e.:
40
41\# commands/cli.cloudservice-tests.js <br />
42\# commands/cli.deployment-tests.js <br />
43commands/cli.site-tests.js <br />
44\# commands/cli.site.appsetting-tests <br />
45
46In the above example only the cli.site-tests.js tests would be run.
47
48#### Recording a particular test in a suite
49
50A test-file can have multiple suites and multiple tests within a suite.
51
52* Executing a specific test from the entire suite: "it.only()"
53```js
54describe.('list', function () {
55 it.only('should work', function (done) {
56 suite.execute('location list --json', function (result) {
57 result.exitStatus.should.equal(0);
58 //verify the command indeed produces something valid such as a well known provider: sql provider
59 var allResources = JSON.parse(result.text);
60 allResources.some(function (res) {
61 return res.name.match(/Microsoft.Sql\/servers/gi);
62 }).should.be.true;
63 done();
64 });
65 });
66
67 it('should not work', function (done) {
68 suite.execute('location list --json', function (result) {
69 result.exitStatus.should.equal(1);
70 //verify the command indeed produces something valid such as a well known provider: sql provider
71 var allResources = JSON.parse(result.text);
72 allResources.some(function (res) {
73 return res.name.match(/Microsoft.Sql\/servers/gi);
74 }).should.be.false;
75 done();
76 });
77 });
78});
79```
80* Skipping an entire suite, will not execute the entire suite. This can de achieved by using the "skip" keyword
81```js
82describe.skip('list', function () {
83 it('should work', function (done) {
84 suite.execute('location list --json', function (result) {
85 result.exitStatus.should.equal(0);
86 //verify the command indeed produces something valid such as a well known provider: sql provider
87 var allResources = JSON.parse(result.text);
88 allResources.some(function (res) {
89 return res.name.match(/Microsoft.Sql\/servers/gi);
90 }).should.be.true;
91 done();
92 });
93 });
94
95 it('should not work', function (done) {
96 suite.execute('location list --json', function (result) {
97 result.exitStatus.should.equal(1);
98 //verify the command indeed produces something valid such as a well known provider: sql provider
99 var allResources = JSON.parse(result.text);
100 allResources.some(function (res) {
101 return res.name.match(/Microsoft.Sql\/servers/gi);
102 }).should.be.false;
103 done();
104 });
105 });
106});
107```
108* Skipping a particular test in a suite. This can be achieved in two ways
109 * it.skip() **OR**
110 * passing null as the second argument to the test
111```js
112describe('list', function () {
113 //The first test will not be run as it is marked skip
114 it.skip('should work', null, function (done) {
115 suite.execute('location list --json', function (result) {
116 result.exitStatus.should.equal(0);
117 //verify the command indeed produces something valid such as a well known provider: sql provider
118 var allResources = JSON.parse(result.text);
119 allResources.some(function (res) {
120 return res.name.match(/Microsoft.Sql\/servers/gi);
121 }).should.be.true;
122 done();
123 });
124 });
125 //The second test will not be run as null is provided as the second argument to the test function.
126 it('should not work', null, function (done) {
127 suite.execute('location list --json', function (result) {
128 result.exitStatus.should.equal(1);
129 //verify the command indeed produces something valid such as a well known provider: sql provider
130 var allResources = JSON.parse(result.text);
131 allResources.some(function (res) {
132 return res.name.match(/Microsoft.Sql\/servers/gi);
133 }).should.be.false;
134 done();
135 });
136 });
137
138 it('should always work', function (done) {
139 suite.execute('location list --json', function (result) {
140 result.exitStatus.should.equal(0);
141 //verify the command indeed produces something valid such as a well known provider: sql provider
142 var allResources = JSON.parse(result.text);
143 allResources.some(function (res) {
144 return res.name.match(/Microsoft.Sql\/servers/gi);
145 }).should.be.false;
146 done();
147 });
148 });
149});
150```