나는 nunit documentation on actions attributes을 읽었으며 모든 테스트 방법에서 특성을 반복하지 않도록하기 위해 Test 메서드 또는 Setup 메서드에서 사용할 수있는 작업 특성을 만들려고합니다. 설치 방법으로 nunit 사용자 지정 작업 특성 사용
나는 다음과 같은 클래스 작성 (워드 프로세서에서 매우 유사,하지만 내가 모든 것을 할 수 있도록 시도 할 경우) :[AttributeUsage(
AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Assembly,
AllowMultiple = true)]
public class CustomActionAttribute : Attribute, ITestAction
{
private string message;
public CustomActionAttribute(string message)
{
this.message = message;
}
public void BeforeTest(TestDetails details)
{
WriteToConsole("Before", details);
}
public void AfterTest(TestDetails details)
{
WriteToConsole("After", details);
}
public ActionTargets Targets
{
get { return ActionTargets.Default | ActionTargets.Suite | ActionTargets.Test; }
}
private void WriteToConsole(string eventMessage, TestDetails details)
{
Console.WriteLine(
"{0} {1}: {2}, from {3}.{4}.",
eventMessage,
details.IsSuite ? "Suite" : "Case",
message,
details.Fixture != null ? details.Fixture.GetType().Name : "{no fixture}",
details.Method != null ? details.Method.Name : "{no method}");
}
}
작동 무엇 :
[Test, CustomAction("TEST")]
public void BasicAssert()
{
}
을 NUNIT에서 테스트 주자 텍스트 출력 패널, 내가 가지고있다
***** Test.CustomerT.BasicAssert
내부 설정
사례 전 : CustomerT.BasicAssert의 TEST.
After Case : TEST, CustomerT.BasicAssert.
무엇을하는 일은하지 작동합니다
[SetUp, CustomAction("SETUP")]
public void CustomAttributeBeforeSetup()
{
System.Diagnostics.Debug.WriteLine("Inside Setup");
}
[Test]
public void BasicAssert()
{
}
을 NUNIT 테스트 러너 텍스트 출력 판넬에서, 나는
이 ***** Test.CustomerT.BasicAssert
내부 설정
?
설치 방법에서 실행할 수있는 사용자 지정 특성을 만드는 방법은 무엇입니까?