我有我的角应用程序,声明如下:
app.module.ts
export class AppModule {}为此,我可以使用ng test MyApp运行测试。
在这个应用程序中,我有多个模块,声明如下:
我的-一个.模组.my/我-其他.模组.my
export class MyOneModule {}
export class MyOtherModule {}这些是在AppModule中导入的。
我怎样才能做像ng test MyOneModule / ng test MyOtherModule这样的事情,用它来运行只运行这个“子模块”中所有组件的测试,而不是应用程序中的所有测试?
我在官方文件或StackOverflow中找不到信息。有可能吗?
发布于 2019-05-15 14:42:24
最后,我使用了这个解决方法:
在test.ts中,我更改路径:
const context: any = require.context('./', true, /\.spec\.ts$/);至
const context: any = require.context('./app/modules/my-one-module', true, /\.spec\.ts$/);或
const context: any = require.context('./app/modules/my-other-module', true, /\.spec\.ts$/);这导致ng test只在定义的目录(及其子目录)中执行测试。
不理想,因为我不喜欢对签入文件进行更改,这些文件并不打算提交,但它完成了工作。
发布于 2022-03-22 16:13:12
您可以单独测试每个模块,而不需要进行任何代码更改。
双副本的test.ts和tsconfig.spec.json文件为模组和重命名如下;
test.moduleone.ts tsconfig.moduleone.spec.json
查找test.ts并在tsconfig.moduleone.spec.json中将其更改为test.moduleone.ts
"files": [
"test.moduleone.ts"
]在test.moduleone.ts中查找并改变路径作为模块路径;
const context: any = require.context('./app/moduleone', true, /\.spec\.ts$/);像这样对模块进行测试;
ng test --main src/test.moduleone.ts --ts-config src/tsconfig.moduleone.spec.json可以将每个模块的脚本添加到package.json中的脚本部分
"scripts":{
"moduleone_tests":"ng test --main src/test.moduleone.ts --ts-config src/tsconfig.moduleone.spec.json"
}因此,您可以使用一个简单的命令来测试每个模块,如
npm run moduleone_tests发布于 2019-05-15 12:31:05
您可以在网上找到一些资源,就像这个,它解释了如何只运行grep文件。
我还记得有一位同事在intelliJ上为单个文件运行他的测试,其中有一个命令行参数,但我完全不记得了。
最后,您还可以在测试中使用fdescribe/xdescribe和fit/xit来运行这些测试。
https://stackoverflow.com/questions/56149258
复制相似问题