问题
I'm brand new to trying to create unit tests but this seems pretty basic and I can't figure out why it is giving me errors. I have a node.js project in Visual Studio. If add one mocha test file as shown below everything works fine:
// file: UnitTest.js
var assert = require('assert');
describe('Test Suite 1', function () {
it('Test 1', function () {
assert.ok(true, "This shouldn't fail");
});
});
describe('Test Suite 7', function () {
it('Test 7', function () {
assert.ok(true, "This shouldn't fail");
});
});
If I click "Run All" in the Test Explorer in Visual Studio the tests execute successfully and all get green check marks. Now, I add another test file named test.js as shown below.
// file: test.js
var assert = require('assert');
describe('test3: 1', function () {
it('test3: 1', function () {
assert.ok(true, "This shouldn't fail");
});
});
This is just another simple test that should succeed. However, when I add that test I now get errors on one of the tests in the UnitTest.js file. Here is what I get:
tests\UnitTest.js (2) --->red X
Test Suite 1 Test 1 (1) --->green check
Test Suite 1 Test 1 --->green check
Test Suite 7 test 7 (1) --->red X
tests\test.js (1) --->green check
test3: 1 test3: 1 (1) --->green check
I can;t fiure out why it fails when I add another test. If I highlight the top level test and click Copy All and paste it to an editor to look for errors I get this:
Group Name: MyApp
Group By: Hierarchy
Group Full Name: MyApp
Duration: 0:00:00.0339074
1 test(s) failed
0 test(s) skipped
2 test(s) passed
Result1 Name: Test Suite 7 Test 7
Result1 Outcome: Failed
Result1 Duration: 0:00:00
Result1 StackTrace:
Result1 Message:
Result1 StandardOutput:
Result1 StandardError:
Result2 Name: Test Suite 1 Test 1
Result2 Outcome: Passed
Result2 Duration: 0:00:00.000998
Result2 StackTrace:
Result2 Message:
Result2 StandardOutput:
Using default Mocha settings
1..2
ok 1 Test Suite 1 Test 1
Result2 StandardError:
Result3 Name: test3: 1 test3: 1
Result3 Outcome: Passed
Result3 Duration: 0:00:00.0329094
Result3 StackTrace:
Result3 Message:
Result3 StandardOutput:
Using default Mocha settings
1..1
ok 1 test3: 1 test3: 1
Result3 StandardError:
What in the heck is going on here? the only thing I notice is that the test that failed has no "Using default Mocha settings" but not sure that really means anything. Maybe it's not there because it failed.
来源:https://stackoverflow.com/questions/60290163/multiple-mocha-tests-fail-if-run-together-in-visual-studio