What would you call a test that is similar to a unit test, except it actually modifies a file, directory, or database data? It is similar to a unit test in that it does test a single method of a single class as opposed to testing an entire feature of a program or a scenario a user would run through. It does not use mocks or stubs like a unit test would.
-
1A problem waiting to reach out and bite you. Tests that change the environment around them tend to be troublesome in the long run, at least in my experience.Michael Kohne– Michael Kohne2016年05月11日 16:12:53 +00:00Commented May 11, 2016 at 16:12
1 Answer 1
That would be an integration test. N.B. you should be doing very few of these (if you do any at all).
Hint: even if you don't call them integration tests, they're certainly not unit tests.
-
6Unit tests are synthetic. They run in a hermetically sealed, sanitized, clean-room environment. Your system can still fall over even with superb unit tests, because you're only testing components in isolation. Even if you don't call them integration tests, you still need them. While I see his point, the author of that article is spreading FUD with a catchy post title and bad math.Robert Harvey– Robert Harvey2016年05月11日 16:30:36 +00:00Commented May 11, 2016 at 16:30
-
1@RobertHarvey For sure - testing doesn't end with unit tests. However, adding rafts of automated integration tests because of a failure during manual testing is the wrong solution for the wrong problem. Unit tests are cheap - you should be writing as many of them as you can.Robbie Dee– Robbie Dee2016年05月11日 16:35:44 +00:00Commented May 11, 2016 at 16:35
-
I think the term "unit test" should be redefined (and is starting to be) to mean you are testing a class, function, or method, as it was designed. So if it was designed to have dependencies or to modify external data, the unit test should do that too. If you use something like mocks to avoid that, you are not really testing the real class/method/function, you are testing a modified version of it. This turns the test into an irrelevant "mock"ery. Most code should be immutable/pure anyway, so it's not a big deal.DivergentSpaceTimeWanderer– DivergentSpaceTimeWanderer2022年12月30日 04:07:00 +00:00Commented Dec 30, 2022 at 4:07
-
@still_dreaming_1 There have been notable strides made by some parties to co-opt myriad questionable practices under the unit testing umbrella to give them undue credence. An excellent rule of thumb is FIRST principles. Fast, Independent, Self-checking, Repeatable and Timely. You don't cite a concrete example, but dependencies (specifically file systems, databases and network services) and modifying external data would be a cause for concern. Not saying the test should be thrown out, it might have some value. But I'd be inclined to run it under a different cadence from bona fide unit tests.Robbie Dee– Robbie Dee2022年12月31日 10:25:59 +00:00Commented Dec 31, 2022 at 10:25