Unit Testing Code with System.Diagnostics.Debug
Matt Ellis has answered Ron Cain’s question about Assert in the context of a test harness. I would answer differently.
When testing code that uses Debug.Assert, you would want to fail the test when that Assert fails. Here is a small piece of code that will do it for you (without needing specialized configuration files, this will keep the test confined in the actual test class and not distributed in several places)
// This Class will fail the test when a Debug.Assert has failed public class TestTraceListener:DefaultTraceListener { public override void Fail(string message, string detailMessage) { Assert.Fail("Debug.Assert Failed: "+message+" "+ detailMessage); } } [Test] public void TestCodeWithFailingDebugAssert() { // use special test tracer Trace.Listeners.Remove("Default"); Trace.Listeners.Add(new TestTraceListener()); // see what happens when a Debug.Assert fails // this is normally hidden somewhere deep inside the code Debug.Assert(false); }
TypeMock is Expanding
If you are reading this you are probably the developer we are looking for.
TypeMock is expanding and we are looking for .NET developers who have a passion for Bleeding Edge Technologies like Mocking (of course), Test Driven Development and Aspect Oriented Development.
We work in a dynamic environment and we have the infrastructure to support home offices for developers who require it.
More information can be found on our Career Page
Send your resume to: jobs@typemock.com
Recent Posts
- Product Status Peek – 2011
- Thanks Roy
- Typemock starts 2011 in a new location
- Agile Demos Smells
- I want loud disputes in our meetings
Categories
- .NET Tests
- Agile
- Code Integrity
- Community
- Debugging
- Fun
- Management for Geeks
- Marketing
- Product
- Release
- Reviews
- SharePoint
- TDD
- Time Management
- Uncategorized
- Unit Tests
Archives
- January 2011
- December 2010
- October 2010
- August 2010
- 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
