maxtimetestcase.cs

来自「NUnit-2.4.1-net-2.0.rar NUnit 测试用例详细的步骤」· CS 代码 · 共 44 行

CS
44
字号
// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
// ****************************************************************

using System;
using System.Reflection;

namespace NUnit.Core.Extensions
{
	/// <summary>
	/// Summary description for MaxTimeTestCase.D:\Dev\NUnit\nunit-2.4\samples\Extensibility\Core\SampleFixtureExtension\Tests\SampleFixtureExtensionTests.cs
	/// </summary>
	public class MaxTimeTestCase : TestCase
	{
		private TestCase testCase;
		private int maxTime = 0;

		public MaxTimeTestCase( TestCase testCase, int maxTime )
			: base( (TestName)testCase.TestName.Clone() )
		{
			// We give it a different test id to avoid confusion
			// when debugging - even though it's not strictly
			// necessary in this case.
			this.TestName.TestID = new TestID();
			this.testCase = testCase;
			this.maxTime = maxTime;
		}

		public override void Run(TestCaseResult result)
		{
			testCase.Run( result );
			if ( result.IsSuccess )
			{
				int elapsedTime = (int)(result.Time * 1000);
				if ( elapsedTime > maxTime )
					result.Failure( string.Format( "Elapsed time of {0}ms exceeds maximum of {1}ms", elapsedTime, maxTime ), null );
			}
		}

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?