잊지 않겠습니다.

NUnit Guide

.NET Framework 2009. 1. 7. 11:11

:NUnit에서 각각의 test를 만들고, 그 Test에서 각각의 Assert문을 만드는 Class library

Constraint

Constraint-base Assert Model을 위한 Class

expect value와 actual value의 비교를 통해 true, false를 결정하고, message를 출력한다.

Assert

Attribute

TestFixtureAttribute

Test Class 선언 Attribute

  • TestFixtureSetUp : Test Class의 모든 Test가 실행되기 전에 수행되는 Test
  • TestAttribute : 각각의 Test
  • TestFixtureTearDown : Test Class의 모든 Test가 실행된 후에 수행되는 Test
  • SetUpAttribute : Test Attribute가 선언된 Test가 각각 실행되기 전에 수행되는 Test
  • TearDownAttribute : Test Attribute가 선언된 Test가 모두 종결될 때 수행되는 Test
SetUpFixtureAttribute
  • 선언된 Namespace에서 한번만 사용될 수 있는 Attribute
  • 모든 TestFixture가 실행되기 전, 모든 TestFixture가 종결될때 단 한번만 수행된다.
CategoryAttribute
  • Test의 종류를 모을 수 있는 Attribute
  • 각각의 Test에서 Category를 이용해서 NUnit.Console 또는 GUI Unit에서 Test의 종류를 모아서 사용 가능하다.
ExceptedExceptionAttribute
  • Exception 무시 처리
ExplicitAttribute
  • 특별하게 GUI또는 Console에서 지정되지 않는 경우에는 수행되지 않는 테스트를 지정한다.
IgnoreAttribute
  • 수행되지 않을 테스트를 지정한다. 이 경우에는 테스트는 Yellow Bar로 나타나게 된다.
  • 임시 테스트로 주로 사용하게 되며, 테스트에 대한 Issue를 적어놓도록 한다.
Description
  • 테스트 또는 Assembly에 대한 설정을 적어놓는 Attribute
[assembly: Description("Assembly description here")]

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture, Description("Fixture description here")]
  public class SomeTests
  {
    [Test, Description("Test description here")]
    public void OneTest()
    { /* ... */ }
  }
}
Property
  • Test가 수행되는 동안에 Property의 값을 지정해 주는 Attribute
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture, Property("Location",723)]
  public class MathTests
  {
    [Test, Property("Severity", "Critical")]
public void AdditionTest()
    { /* ... */ }
  }
}
IncludeExcludeAttribute (abstract)
  • Include, Exclude를 이용, Test의 수행 환경을 결정한다.
PlatformAttribute
  • Test가 수행될 환경 결정
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class SuccessTests
  {
    [Test]
    [Platform(Exclude="Win98,WinME")]
    public void SomeTest()
    { /* ... */ }
}
Win Win32 Win32S Win32Windows Win32NT WinCE Win95 Win98 WinMe NT3 NT4 NT5 Win2K WinXP Win2003Server Unix Linux Net Net-1.0 Net-1.1 Net-2.0 NetCF SSCLI Rotor Mono
CultureAttribue
  • 테스트가 수행될 언어 환경 설정
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  [Culture("fr-FR")]
  public class FrenchCultureTests
  {
    // ...
  }
}
Posted by Y2K
,