When setting up unit tests (in my case, using Jasmine for JavaScript) should the un-minified/in-uglified src
files be tested? Or should the end-user build
files (minified and uglified) be tested?
In my grunt config:
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.
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.
There is a general rule to be cautious of writing unit tests that do file I/O, because they tend to be too slow. But there is no absolute prohibition on file I/O in unit tests. In your unit tests have a temporary directory set up and torn down, and create test files and directories within that temporary directory.
Yes, you should test your repository layer. Although the majority of these tests fall into a different classification of tests. I usually refer to them as integration tests to distinguish them from my unit tests.
The developers should write unit tests alongside the source code and execute them in pipelines. Separating the repositories keeps more clean environment.
The most popular option to verify the output when testing the void method is to use the mock object. A mock object is an object that replicates the behavior of a real object for the purposes of unit testing. For example, you can observe how the class under test calls the dependency with a mock object.
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.
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)
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.
I think this goes under the End-to-end testing category - imitating a real user, going through acceptance-testing scenarios, user stories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With