4 ms·
Hmm, having a test do anything more than one thing sounds like a functional or integration test.
by lcarlson 10y ago
Hmm, having a test do anything more than one thing sounds like a functional or integration test.
- raverbashing 10y agoDefine "one thing" Suppose you want to test a function that capitalizes the first letter of words in a string: I would test '' => '' 'a' => 'A' 'aa bb' => 'Aa Bb' 3 tests, which does not mean 3 functions (that will have the overhead of setup and teardown)
- flukus 10y agoI would make this a parameterized test for those common use cases and specific test for others ("o'tool" => "O'Tool"). The overhead of setup/teardown should be practically zero. Even having them as 3 separate functions should be take fractions of a millisecond. The important thing is, it should be obvious why a test failed, you don't want more then 1 or two asserts.
- Almaviva 10y agoDo the test run quickly, are they clear and readable, do they help find regression problems, is it reasonably easy to tell what went wrong when they fail, does the time and effort and peace of mind saved exceed that invested (over the life of the project, amortized, sometimes, for the value of iterating quickly)? These are important questions, whether you call a test integration, functional, or unit, is not an important question.