Great Time in Tech Ed Barcelona
We had a great time in Barcelona, The TechEd team has done it again and have created a top-notch conference. Apart from not being able to get tickets to the Barcelona Football match, we practically had everything made out for us.
We had some really good talks and met up with great people from the industry. Thank you all.
TypeMock is a Silver Bullet
During the TechEd in Bacelona, I overheard developers talking about TDD and Mocking. Then I heard one of them say that TypeMock is a Silver Bullet, it can just help you solve all your mocking problems. I love that, thanks guys.
Roys Test Name Convention
I just loved the way Roy explained how developers normally name their tests without really thinking about them. for example SumNegitiveNumber5 (yup, I have been down that road before) and his naming convention really make sense.
But what I really liked was the template he wrote and how the Tab key browses through the three the different parts of the name.
Rollback for database testing
Roy Osherove had a good speak in TechEd Barcelona 2007, about using the roll back attribute for database testing, and it works really well, keeping the test case isolated. Except in cases where the production code ignores transactions that are higher up in the hierarchy. This will happen if the TransactionOption is RequiresNew
Roy suggested to always use: Supported, but we believe that there should be a way to test you code even if you require and need to use another transactions.
So here is how I would do it with TypeMock.
I would create a new attribute for the rollback and make sure that all future TransactionOptions are Mocked.
This way our test will look like:
[TestMethod,Rollback,VerifyMocks]
public void MyDatabaseTest()
{
}
Here is the code, to enable this (for any test framework) simple add the attribute.
[AttributeUsage(AttributeTargets.Method)]
public sealed class RollBackAttribute : DecoratorAttribute
{
public override object Execute()
{
// Start transaction
ServiceConfig config = new ServiceConfig();
config.Transaction = TransactionOption.RequiresNew;
ServiceDomain.Enter(config);
// make sure that all future Transactions rely on this transaction by mocking all sets to the Transaction
Mock serviceConfigMock = MockManager.MockAll<ServiceConfig>(Constructor.NotMocked);
serviceConfigMock.ExpectSetAlways("Transaction");
try
{
// run our tests
return base.CallDecoratedMethod();
} finally
{
// clear unused mocks
serviceConfigMock.Clear();
// rollback database
if(ContextUtil.IsInTransaction)
{
ContextUtil.SetAbort();
}
ServiceDomain.Leave();
}
}
}
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
