简体   繁体   English

我应该单元测试我的/ src文件或/ build文件吗?

[英]Should I unit test my /src files or /build files?

When setting up unit tests (in my case, using Jasmine for JavaScript) should the un-minified/in-uglified src files be tested? 在设置单元测试(在我的情况下,使用Jasmine for JavaScript)时,是否应测试未缩小/未使用的src文件? Or should the end-user build files (minified and uglified) be tested? 或者应该测试最终用户build文件(缩小和uglified)?

In my grunt config: 在我的grunt配置中:

jasmine: {
    src: ['src/file.js']
}

vs.

jasmine: {
    src: ['build/file.min.js']
}

On one hand, it's nice to test the src files since it doesn't remove debuggers and is easier to inspect when needed. 一方面,测试src文件很好,因为它不会删除调试器,并且在需要时更容易检查。

On the other hand, I can test the src files as much as I like but it's not true to what the end users will be running, as the build files are uglified and minified. 另一方面,我可以尽可能多地测试src文件,但最终用户将不会运行,因为build文件已经过化和缩小。

You should definitely unit test the bare source files as there were written. 你应该像编写的那样对裸源文件进行单元测试。 Unit tests are designed to be tightly focused and give you instant and clear feedback . 单元测试旨在紧密集中,为您提供即时,清晰的反馈 In other words, if you test your functionality after the source code being modified - you are not testing your code in isolation; 换句话说,如果您在修改源代码后测试您的功能 - 您不是孤立地测试您的代码; once you discover a bug, you cannot be 100% sure what caused it - it could be that there was a problem during the build that caused the problem - say the uglify task. 一旦你发现了一个bug,就不能100%肯定是什么导致了它 - 可能是在构建过程中出现了导致问题的问题 - 比如uglify任务。

I would classify testing build files as a part of integration or a higher-level testing - since aside from testing functionality, you are also checking how your application was built: how the files were minified, copied, concatenated etc. 我将测试构建文件归类为集成或更高级别测试的一部分 - 除了测试功能之外,您还要检查应用程序的构建方式:文件如何缩小,复制,连接等。

In general, you should aim to the following pyramid: 一般来说,您应该瞄准以下金字塔:

在此输入图像描述

( introduced in this Google Test Automation blogpost ) 在Google Test Automation博客中引入

On the other hand, I can test the src files as much as I like but it's not true to what the end users will be running, as the build files are uglified and minified. 另一方面,我可以尽可能多地测试src文件,但最终用户将不会运行,因为构建文件已经过化和缩小。

I think this goes under the End-to-end testing category - imitating a real user, going through acceptance-testing scenarios, user stories. 我认为这属于端到端测试类别 - 模仿真实用户,通过验收测试场景,用户故事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM