Created
April 26, 2016 04:00
-
-
Save TheOpenDevProject/6356de1e38aa8f99169f460d8d09e8fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Diagnostics; | |
using System.Reflection; | |
namespace TestFramework | |
{ | |
public class TestFrameworkAttribute : Attribute{ | |
} | |
public abstract class TestFrameworkClass{ | |
} | |
public class TestRunner | |
{ | |
private TestFrameworkClass _NTests; | |
public TestRunner(TestFrameworkClass ClassToTest) | |
{ | |
_NTests = ClassToTest; | |
} | |
public void Run() | |
{ | |
MethodInfo[] Tests = _NTests.GetType().GetMethods(); | |
foreach (MethodInfo CurrentTest in Tests) | |
{ | |
var attributes = CurrentTest.GetCustomAttributes(typeof(TestFrameworkAttribute), false); | |
if (attributes.Length > 0) | |
{ | |
try | |
{ | |
CurrentTest.Invoke(_NTests, null); | |
} | |
catch (Exception ex) | |
{ | |
throw ex.InnerException; | |
} | |
} | |
} | |
} | |
} | |
public class FrameworkTest : TestFrameworkClass | |
{ | |
[TestFrameworkAttribute()] | |
public void TestOne() { | |
Debug.WriteLine("This is a test framework and working"); | |
} | |
[TestFrameworkAttribute()] | |
public void TestTwo() { | |
Debug.WriteLine("Also a test method"); | |
} | |
[TestFrameworkAttribute()] | |
public void AnotherTestThatFails() | |
{ | |
throw new ArgumentException("This test failed."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment