Unit Testing the Metric Dashboard – Part 3

Continuation of unit testing the Metric Dashboard.

Watching for new files

The Dashboard listens to the test result folder for new files. As this is done in another thread, the test must wait for the file to be read and processed in order to verify that the feature works. In the older versions of Typemock there was a VerifyWithTimeout api. Here is a hack to do the same with the lambda API’s. This test is actually an interesting test

Unit testing

  1. I delete the file before copying just to be sure.
  2. Here I am faking the current date to be the same as the date of the test – this is so that I get the correct value from CurrentProtection
  3. Hack to Wait for Load() to be called. In this hack I set an event once the method has been called and then I call the real Load() method.
  4. Copy file to watched location
  5. Wait for Load to be called
  6. Here a short wait is needed for the method to complete.
  1. Wouldn’t it be easier to switch the lines inside the “WhenCalled” expression, so the even gets set after the Load performs? You won’t need the Sleep(100) at the end. Or am I missing something?

  2. Yup, that would be a good way.
    It just seems a bit brittle.

    I would prefer to do something like:
    Wait for delegate that is run on another thread to complete.

Add Comment

Required fields are marked *. Your email address will not be published.