C# 애플리케이션의 단위시험에 사용할 도구를 정하고자 한다. 단위시험 도구로는 'JUnit'이 가장 먼저 떠오르고, 이와 연상되는 'NUnit'이 있다.
JUnit을 .NET 프레임워크 기반으로 포팅한 결과물로 NUnit 이외에 MbUnit, csUnit 등이 있다. 이들 다수가 오픈소스인데, 그 중에서도 xUnit.NET 프로젝트가 돋보인다.
홈페이지에서 'Abount the Project' 문서를 보면서, xUnit.NET 개발 동기(Why did we build xUnit.net?)에 크게 공감한다. 무엇보다도, 개발 동기를 밝힌 문서에서 'Lessons Learned'를 눈여겨 봐 둘만 하다. (아래에 복사해둔다.)
Lessons Learned
- Single Object Instance per Test Method. Much has been written about why this improves test isolation. In xUnit.net we create a new instance per test. For more information, see http://blogs.msdn.com/jamesnewkirk/archive/2004/12/04/275172.aspx and http://martinfowler.com/bliki/JunitNewInstance.html.
- No [SetUp] or [TearDown]. I blogged recently about some of the problems related to SetUp/TearDown. xUnit.net does not have any built-in support for this capability. For more information, see http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html.
- No [ExpectedException]. Rather that decorating a method with an attribute, we have returned to the old JUnit style of Assert.Throws for expected exceptions. This helps two major issues: 1. With [ExpectedException] it's possible to hide real errors when the wrong method call throws an exception, and 2. Allows your tests to continue to obey the Arrange-Act-Assert (or "3A") pattern, as coined by William Wake.
- Aspect-Like Functionality. End users extended NUnit and MbUnit with cross-cutting concerns that could be attached to test methods (an example is automatically rolling back changes made to a database during the test). This made the tests simpler to write and allowed more consistent usage of the cross-cutting operations. xUnit.net makes it very simple to create such operations and attach them to test methods.
- Reducing the Number of Custom Attributes. Sometimes, the excessive use of attributes can make you feel like you've diverged far from the underlying language. xUnit.net removed some attributes from the framework, instead relying on language features to provide similar functionality:
- [TestFixture] was removed entirely; tests can be in any public class. Test methods can be static or instance, to better facilitate testing with F#.
- [Ignore] is expressed using the Skip= parameter on [Test].
- [SetUp] and [TearDown] are removed in favor of constructors and IDisposable.
- [ExpectedException] was replaced with Assert.Throws (or Record.Exception, which provides better adherence to the 3A pattern).
- [TestFixtureSetup] and [TestFixtureTearDown] are removed in favor of implementing reusable fixture data classes, which are attached to test classes by having them implement IUseFixture<T>.
그리고, 홈페이지에서, NUnit 등과 같은 다른 도구들과 기능을 비교, 정리해서 제공하고 있어 도구들의 기능 유사성을 구별하는 데 많은 도움이 되었다.
xUnit.NET은 다수의 실행 프로그램을 제공 (MSBuild, TestDriven.NET, ReSharper, console-based, GUI-based 등), Microsoft .NET Framework 3.5 버전을 지원하는 것이, 비교 자료에는 보이지 않지만, 가장 특징적이라고 생각한다.


이올린에 북마크하기
이올린에 추천하기

