An example of bad test, part 1

Let us take a look at this test. When I saw it, the test cried out in pain to me: "Help me, I am so overworked."

image

This test is doing far too much. I drew the battle line on the test, just to give you a clear indication on what is going on.

image

What we are asserting are things that have nothing to do with what the test is supposed to test.This is also the classic "A test should have a single assertion" example, I think.

The test pass by side effect. It will actually be a problem down the line.

Print | posted on Sunday, August 17, 2008 5:39 AM

Feedback


Gravatar

# re: An example of bad test, part 1 8/17/2008 6:03 AM Rob Conery

Ayende this is a spike, as I mentioned about 5 times on my blog and in the video. I understand the issue you're having here - I just wanted to see if it would work. It did...


Gravatar

# re: An example of bad test, part 1 8/17/2008 6:11 AM Rob Conery

Also - it's worth mentioning that I have no idea how to unit test something that is fired in an asynch way. In other words, WWF uses the WorflowRuntime, which is off on its own thread. I have a race condition in this code but believe it or not - the result came in :) and I was happy.

Now that said - what I could do is start and then stop the runtime - wait for it, and then see what the status of the order is... thoughts?


Gravatar

# re: An example of bad test, part 1 8/17/2008 6:19 AM Ayende Rahien

Rob,
Just to clarify.
Spike code has no standards, agreed.
It just turned out to be a good example to show bad testing practices.


Gravatar

# re: An example of bad test, part 1 8/17/2008 6:20 AM Ayende Rahien

Testing async code is tough.
ManualResetEvent is the common case.


Gravatar

# re: An example of bad test, part 1 8/18/2008 12:34 PM IVR

Well, it looks like C#, is it?

Comments have been closed on this topic.