コード例 #1
0
ファイル: UnitTestTask.cs プロジェクト: jonathanvdc/Loyc
		protected override void RunCore()
		{
			if (!RunAndCatch(() => { var inst = Instance; }, "constructor"))
				return;

			// Try creating a delegate before starting any Stopwatch, so that for
			// benchmarking purposes we avoid measuring the cost of reflection.
			Action invokeTest = null;
			if (Method.ReturnType == typeof(void)) {
				try {
					invokeTest = (Action)Delegate.CreateDelegate(typeof(Action), Instance, Method);
				} catch { }
			}

			// TODO: Setup method

			object result = null;
			Statistic runTimes = null;
			TimeSpan runTime;
			if (MinTrials.HasValue || RepeatForMs.HasValue) {
				int minTrials = MinTrials ?? 0;
				int repeatForMs = RepeatForMs ?? 0;
				int trial = 0;
				runTimes = new Statistic();
				SimpleTimer timer = new SimpleTimer();
				do {
					result = RunOnce(invokeTest, out runTime);
					runTimes.Add(runTime.TotalMilliseconds);
				} while (++trial < minTrials && timer.Millisec < repeatForMs);
				RunTime = TimeSpan.FromMilliseconds(timer.Millisec);
			} else {
				result = RunOnce(invokeTest, out runTime);
				RunTime = runTime;
			}

			if (Status == TestStatus.Running)
				Summary = BuildSummary(result, runTimes);

			// TODO: Teardown method
		}
コード例 #2
0
ファイル: UnitTestTask.cs プロジェクト: jonathanvdc/Loyc
		private string BuildSummary(object result, Statistic runTimes)
		{
			string msg = "Passed";
			if (runTimes != null && runTimes.Count > 1)
			{
				msg = string.Format("{1} trials; average {2:0.000} seconds, min {3:0.000}, max {4:0.000}, std.dev. {5:0.000})",
					msg, runTimes.Count, runTimes.Avg(), runTimes.Min, runTimes.Max, runTimes.StdDeviation());
			}
			if (result != null)
			{
				Status = TestStatus.SuccessWithMessage;
				msg = string.Format("{0} - {1}", msg, result);
			}
			else
				Status = TestStatus.Success;
			return msg;
		}