-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestResult.cs
More file actions
82 lines (71 loc) · 2.54 KB
/
TestResult.cs
File metadata and controls
82 lines (71 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using NinjaTrader.Cbi;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace NinjaTrader.UnitTest
{
public class TestResult
{
public int RunCount => SuccessCount + FailureCount + ErrorCount;
public List<string> Successes { get; } = new List<string>();
public List<(string, Exception)> Errors { get; } = new List<(string, Exception)>();
public List<(string, Exception)> Failures { get; } = new List<(string, Exception)>();
public double Duration { get; private set; }
public int FailureCount => Failures.Count;
public int ErrorCount => Errors.Count;
public int SuccessCount => Successes.Count;
public TestResult(bool verbose = true)
{
this.verbose = verbose;
}
internal virtual void AddSuccess(string testCase)
{
Successes.Add(testCase);
if (verbose)
{
NinjaTrader.NinjaScript.NinjaScript.Log($"{testCase} ... OK", LogLevel.Information);
}
}
public virtual void AddFailure(string testCase, Exception exception)
{
Failures.Add((testCase, exception));
if (verbose)
{
NinjaTrader.NinjaScript.NinjaScript.Log($"{testCase} ... FAIL: {exception.Message}", LogLevel.Warning);
}
}
public virtual void AddError(string testCase, Exception exception)
{
Errors.Add((testCase, exception));
if (verbose)
{
NinjaTrader.NinjaScript.NinjaScript.Log($"{testCase} ... ERROR: {exception.Message}", LogLevel.Error);
}
}
public virtual void AddSubTest(string testCase, SubTest subTest, string exception)
{
}
internal void AddTime(double duration)
{
Duration += duration;
}
public bool WasSuccessful()
{
return (FailureCount == 0 && ErrorCount == 0);
}
public void PrintSummary()
{
NinjaTrader.NinjaScript.NinjaScript.Log($"Ran {RunCount} tests in {Duration:F3}s", LogLevel.Information);
if (WasSuccessful())
{
NinjaTrader.NinjaScript.NinjaScript.Log("OK", LogLevel.Information);
}
else
{
NinjaTrader.NinjaScript.NinjaScript.Log($"FAILED (failures={FailureCount}, errors={ErrorCount})", LogLevel.Error);
}
}
private bool verbose = true;
}
}