Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheOpenDevProject/6356de1e38aa8f99169f460d8d09e8fc to your computer and use it in GitHub Desktop.
Save TheOpenDevProject/6356de1e38aa8f99169f460d8d09e8fc to your computer and use it in GitHub Desktop.
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