I was told that unittest is fast and the tests which touches DB, across network, and touches FileSystem are not unittest.
In one of my testcases, its input are the file names (amount about 300~400) under a specific folder. Although these input are part of file system, the execution time of this test is very fast.
Should I moved this test, which is fast but touches file system, to higher level test?
3
Speed shouldn’t be the only determination when figuring out what type of test you are writing / running. A SQL query could take 10 milliseconds, which could be considered fast. Reading from a file on a system could take 5 milliseconds, which too could also be considered fast.
Here are some of common criteria for determining if something is a unit test (this list is not all inclusive):
- Has no external dependencies (sql server, file server, network, …)
- Repeatable results, if the code doesn’t change then the test results shouldn’t change
- Fully isolated, one test should not depend on another test to run
- Finally, be fast
Your test touches the file system, which fails two of the above four criteria. If the folder is renamed, a file is removed, or the network connection fails, then your test could fail. This means it is a integration test, or from what you wrote in the “fulltest” project. Integration tests are still important and are useful. If you want to make your test a true unit test then I would follow the links @gnat provided.
2