Home > Web Front-end > JS Tutorial > body text

Angular implementation only executes new unit tests under development

青灯夜游
Release: 2021-02-01 11:47:01
forward
3524 people have browsed it

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.

Angular implementation only executes new unit tests under development

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$/);
Copy after login

Angular implementation only executes new unit tests under development

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);
Copy after login

Put the path of the unit test file that needs to be executed into the FILE array:

Angular implementation only executes new unit tests under development

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:

Angular implementation only executes new unit tests under development

Angular implementation only executes new unit tests under development

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!