Natural Mocks becoming more intelligent
Natural Mocks automatically mocks everything. This includes return values. So the following code:
using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork(); recorder.Return(new SqlInt32(1)); }
Won’t work as expected because SqlInt32 is being mocked.
This has bugged me a few times and I simply created the return value outside the recorder.
SqlInt32 mockValue = new SqlInt32(1)); using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork(); recorder.Return(mockValue); }
But this is not really nice, and a few customers have pointed out that this could be annoying!
So we are going to implement a feature that will know that you are creating a return value and will not mock it!
This way the first code will work as expected. Of course if you want to return a mocked value you will have to create the mock before, this might lead to non backward compatibility.
To those who want the first code to work as before (although I don’t think that anyone would), mock the return value before calling the recorded statements, and change the above code to:
using (RecordedExpecations recorder = RecorderManager.StartRecording()) { SqlInt32 mock = new SqlInt32(1); DummyClass.DoWork(); recorder.Return(mock); }
Of course if you are going to do that, you will have to define the behavior of the SqlInt32 and you might as well use ChainedMocks
using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork().Value; recorder.Return(1); }
What do you think about this feature?
1 Comment to “Natural Mocks becoming more intelligent”
Recent Posts
- Unacceptable: Unit testing will take 20 years to catch on
- The 4 reasons why we DIDN’T choose Oslo
- Typemock Academy Launch
- The First Rule to Software Craftsmanship
- Goal-driven Development
Categories
- .NET Tests
- Agile
- Code Integrity
- Community
- Debugging
- Fun
- Management for Geeks
- Marketing
- Product
- Release
- Reviews
- SharePoint
- TDD
- Time Management
- Uncategorized
- Unit Tests
Archives
- May 2010
- April 2010
- March 2010
- February 2010
- December 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- August 2008
- July 2008
- May 2008
- April 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006

[...] Deep - Perhaps supporting Multi-Threads could be called deep.Intelligent – Well we just got more intelligent (Perhaps one day TypeMock will write the mocks itself)Complete – We are trying to give a complete solution. We have a Pre-Sales and Support Group although I know that we need more examples and training materialsElegant – I think that NaturalMocks is.Emotize – Hmm? Do you feel passionate about TypeMock? [...]