TDD: Testing with Stub Methods

Please see my other Test Driven Development articles.

Adding flexibility to return values using Stub methods.

Continuing on my “Testing with Dummy objects” article, you might have noticed a limitation with regards to the return value – only one was allowed.
In situations where multiple return values are needed, Stub methods provide an alternative.

1-tdd-testing-with-stubs

2-tdd-testing-with-stubs

In my previous example, GetSalesOutcome() only provided one return value.
However, if I need my test method to return multiple values for more flexible testing, I may rewrite my test method to accommodate that need.

3-tdd-testing-with-stubs

4-tdd-testing-with-stubs

As you can see, the test still passes, but now I am able to use a much more flexible test, in this case testing for multiple sales associates.

5-tdd-testing-with-stubs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s