Home > Article > Web Front-end > Angular implementation only executes new unit tests under development
AngularHow can unit testing only execute specified test cases to improve testing speed? The following article will introduce it to you. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Related tutorial recommendations: "angular Tutorial"
Once the size of the Angular project increases, the number of unit tests to be executed will Probably massive. At this time, when developing new unit tests, you will encounter tests that are already very stable in the system and need to be shielded, and only the new unit tests under development will be executed. How to realize this requirement?
There is test.ts in each Angular project folder. There is a line of statements in it that specifies which unit tests in the ts files under the project will be executed:
const context = require.context('./', true, /\.spec\.ts$/);
By default, the unit tests contained in all files ending with .spec.ts in the src directory will be executed.
If I want to only execute the new unit tests being developed and block all previously developed unit tests, I can make a fuss about the structure returned by require.context.
You only need to add the following two lines of statements:
const FILE = ['./app/ngrxdemo/service/unittest-study/demo.spec.ts']; context.keys().filter( name => !!FILE.includes(name)).map(context);
Put the path of the unit test file that needs to be executed into the FILE array:
Run ng test on the command line, and you can observe that only the test cases in demo.spec.ts, a unit test file specified in the FILE array, have been executed:
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of Angular implementation only executes new unit tests under development. For more information, please follow other related articles on the PHP Chinese website!