-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomTestRunner.cs
More file actions
81 lines (75 loc) · 3.07 KB
/
CustomTestRunner.cs
File metadata and controls
81 lines (75 loc) · 3.07 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
using System;
using System.Reflection;
namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
public class TestClassAttribute : Attribute {}
public class TestMethodAttribute : Attribute {}
public static class Assert
{
public static void AreEqual(object a, object b)
{
if (a == null && b == null) return;
if (a == null || !a.Equals(b)) throw new Exception(string.Format("Expected '{0}', got '{1}'", a, b));
}
}
public static class CollectionAssert
{
public static void AreEqual(byte[] a, byte[] b)
{
if (a == null && b == null) return;
if (a == null || b == null || a.Length != b.Length) throw new Exception("Collections lengths differ");
for(int i=0; i<a.Length; i++)
{
if (a[i] != b[i]) throw new Exception(string.Format("Collections differ at index {0}. Expected {1}, got {2}", i, a[i], b[i]));
}
}
}
}
namespace CustomRunner
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("========================================");
Console.WriteLine(" EXECUTION DES TESTS UNITAIRES AES ");
Console.WriteLine("========================================");
int passed = 0;
int failed = 0;
var testClassType = typeof(UnitTestProject.UnitTestAes);
var testInstance = Activator.CreateInstance(testClassType);
foreach (var method in testClassType.GetMethods())
{
var attrs = method.GetCustomAttributes(typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute), false);
if (attrs.Length > 0)
{
Console.Write(string.Format("Running test {0}... ", method.Name));
var oldOut = Console.Out;
var sw = new System.IO.StringWriter();
Console.SetOut(sw);
try
{
method.Invoke(testInstance, null);
Console.SetOut(oldOut);
Console.WriteLine("PASSED");
passed++;
}
catch (Exception ex)
{
Console.SetOut(oldOut);
Console.WriteLine("FAILED");
Console.WriteLine(string.Format(" Exception: {0}", ex.InnerException != null ? ex.InnerException.Message : ex.Message));
failed++;
}
finally
{
Console.SetOut(oldOut);
}
}
}
Console.WriteLine("========================================");
Console.WriteLine(string.Format("Tests run: {0}, Passed: {1}, Failed: {2}", passed + failed, passed, failed));
Console.WriteLine("========================================");
}
}
}