Test driven development and threading?

D

DeveloperX

Hi, I'm struggling to work out how to unit test threading. Is there
any advice out there? I'll take books, blogs and especially your
experience.

I can't be more specific, I just don't know how to approach unit
testing where threads are involved.

Thanks
DevX
 
C

Cowboy \(Gregory A. Beamer\)

The unit test is testing the functionality of a single routine, in
isolation. This would mean you would test like so:

1. Test the routine that spins up the thread with some form of dependency
injection - you are just testing to make sure the call is being sent
correctly
2. Test the thread routines as regular routines, seeing if they get the
correct answer

When you get to an Integration test scenario you will actually have to spin
things up and ensure they are working. Until then, try to focus as tightly
as possible.

Remember, you are testing your code, not whether or not Microsoft's method
of opening threads works.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
D

DeveloperX

The unit test is testing the functionality of a single routine, in
isolation. This would mean you would test like so:

1. Test the routine that spins up the thread with some form of dependency
injection - you are just testing to make sure the call is being sent
correctly
2. Test the thread routines as regular routines, seeing if they get the
correct answer

When you get to an Integration test scenario you will actually have to spin
things up and ensure they are working. Until then, try to focus as tightly
as possible.

Remember, you are testing your code, not whether or not Microsoft's method
of opening threads works.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my bloghttp://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|

That makes sense, but can I unit test for things like blocking? This
might sound daft, but I've never tried. I know how threading works, I
know what to look for and where to lock, but I can't see anyway to fit
that into a TDD approach. Can I prove that my approach to locking
works?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top