Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- public class Program
- {
- public static void Main()
- {
- TestRunner.Run(new Program());
- }
- public void test1(){
- Assert.AreEqual(1,2);
- }
- }
- public static class TestRunner{
- public static void Run(object target){
- var mi = target.GetType().GetMethods(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);
- int passed=0,failed=0;
- foreach(var m in mi){
- var argCount = m.GetParameters().Length;
- var isVoid=m.ReturnType == typeof(void);
- if (argCount==0 && isVoid){
- Console.WriteLine("> "+m.Name);
- try{
- m.Invoke(target, null);
- Console.WriteLine("\tPassed");
- passed++;
- }catch(TargetInvocationException tex) {
- if (tex.InnerException is Failed){
- var f = tex.InnerException as Failed;
- Console.WriteLine("Failed "+f.Message);
- failed++;
- }else{throw;}
- }
- }
- }
- Console.WriteLine("Total: "+(passed+failed)+", Passed: "+passed+", Failed: "+failed);
- }
- }
- class Failed:Exception{
- public Failed(string message):base(message){}
- }
- public static class Assert{
- public static void AreEqual(object expected, object actual){
- if (expected.GetType() != actual.GetType()){
- throw new Failed("Types are not equal");
- }
- if (!expected.Equals(actual)){
- var q=(actual is string)?"\"":"";
- throw new Failed("Values are not equal,\n\texpected "+q+expected+q+"\n\tactual "+q+actual+q);
- }
- }
- public static void IsNull(object expected){
- if (expected!=null){
- throw new Failed("Expected null");
- }
- }
- public static void NotNull(object expected){
- if (expected==null){
- throw new Failed("Expected not null");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement