U E D R , A S I H C RSS

NUnit/C#예제

  1. C# 관련 를 만든다. (브러리)
  2. 기를 -> PopUp NUnit nunit.framework
  3. 는 Method 는 Test를, TestFixture Attribute를 붙다.
    1. SetUp TearDown 기능 당 Attribute를 다.
  4. NUnit gui나 console 브라로 빌드 dll exe를 로딩 Test를 다.

~cpp 
using System;
using System.IO;
using NUnit.Framework;
namespace NUnitByCShop
{	
	[TestFixture]
	public class AssertTester
	{
		[Test] public void 더빼기()
		{
			int actual = 3+2, expected = 5;
			Assertion.AssertEquals(expected,actual);			
			Assertion.Assert(actual == expected);
		}		
		[Test]
		public void Null값검()
		{
			int[] activeArray = {1,2,3};
			Assertion.AssertNotNull(activeArray);
			int[] nullArray = null;
			Assertion.AssertNull(nullArray);
		}
		[Test]
		public void ()
		{
			Assertion.AssertEquals(5,3+4);
		}
	}
	[TestFixture]
	public class FileTester
	{		
		String fileName = "_________Test";	
		[SetUp] public  void 만들기()
		{		
			FileInfo fileInfo = new FileInfo(fileName);
			FileStream fileStream = fileInfo.Create();			
			fileStream.WriteByte(12);
			fileStream.Flush();
			fileStream.Close();
		}
		[TearDown] public void 기()
		{
			FileInfo fileInfo = new FileInfo(fileName);
			fileInfo.Delete();
		}
		[Test] public void ()
		{                    
			FileInfo fileInfo = new FileInfo(fileName);
			Assertion.Assert(fileInfo.Exists);
		}
	}
}
결과
NunitByC#ExampleGui.gif
NunitByC#ExampleConsole.gif

UnitTest

대로 는 다른 xUnit 다. 만 몇 가 다.

  • 명령 만들기
  • 메뉴 구(tool)로 다.
  • External Tools 른다.
  • 는 Add를 른다.
  • 는 Title기가 ( :NUnit Test(Console) ) 는다.
  • Command NUnit 로그램 경로를 다.(:C:\Program Files\NUnit 2.2\bin\nunit-console.exe)
  • Argument $(ProjectDir)\bin\debug\$(TargetName).exe 라고 는다. ( 보그 모드 므로 더가 debug다. 릴리는 release로 바꾸면 될 듯)
  • 만 Use Output Window를 Output로 결과가 나다.
  • 만들기
  • 메뉴 는 Tool 른다.
  • Customize를 른다.
  • Keyboard를 른다.
  • Show Command Containing 밑 는 박 구를 다. 때 명령 므로 NUnit 는 것 명령(External Command) 다. 구를 다면 External Command8 다. (VS2005부명령1 External Tools)
  • Press Shotcut Key(s) 부 는 단 다. (: Ctrl + ' )
  • 르고 르면 다.!!
----
NUnit
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:50
Processing time 0.0129 sec