c# - What's the best practice in organizing test methods that cover steps of a behavior? -
i have fileextractor
class start
method steps.
i've created test class called "whenextractinginvalidfile.cs" within folder called "fileextractortests" , added test methods inside below should verified steps of start() method:
[testmethod] public void should_remove_original_file() { } [testmethod] public void should_add_original_file_to_errorstorage() { } [testmethod] public void should_log_error_locally() { }
this way, it'd nicely organize behaviors , expectations should met.
the problem of logic of these test methods same should creating 1 test method verifies steps or separately above?
[testmethod] public void should_remove_original_file_then_add_original_file_to_errorstorage_then_log_error_locally() { }
what's best practice?
while it's commonly accepted act section of tests should contain 1 call, there's still lot of debate on "one assert per test" practice.
i tend adhere because :
when test fails, know (from test name) of multiple things want verify on method under test went wrong.
tests imply mocking harder read regular tests, can arcane when you're asserting against multiple mocks in same test.
if don't follow it, i'd @ least recommend include meaningful assert messages in order minimize head scratching when test fails.
Comments
Post a Comment