Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Unless you are unit testing a file utility class, if you access files during your test, you exceeding the scope of unit that you should be testing

However, there are more pragmatic reasons to consider as well.

Clarity / Evident Data

Many times, the motivation for accessing files is to read test data upon which the class under test depends. Separating test data from the code of your test makes that test significantly harder to understand and debug. Kent Beck refers to this unit testing best practice as Evident Data. Show the reader of your test the intent of the code being tested by using clear and understandable data as parameters. Once you move that data into a separate file, especiall in binary formats, the maintenance cost and usefulness of that test becomes significantly worse.

Speed of execution

If Ashcroft fails your unit test because some class was reading or writing to a file, you will be in one of the following cases:

  1. Some of your own code in your SUT was trying to do file I/O
  2. Your test was trying to do file I/O
  3. Some code that your SUT or test is using was trying to do file I/O
  • No labels