Tests/src/Tests.cs
/// <summary>
/// To run tests by means of introspection.
/// Executes all the methods that start with "test"
/// </summary>
/// <param name="klass">The class where testing methods are placed</param>
/// <param name="errorsFound">The list of errors. Key=methodName, Value=[expectedErrors, errorsFound]</param>
To run tests by means of introspection.
Executes all the methods that start with "test"
To run tests by means of introspection . Executes all the methods that start with " test "
private static int test(Type klass, IDictionary<string, int[]> errorsFound) {
            object obj = klass.GetConstructor(new Type[0]).Invoke(null);
            MethodInfo[] methods = klass.GetMethods();
            int n = 0;
#if DEBUG
            ConsoleColor previousColor = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("> Executing tests the '{0}' class:", klass.Name);
#endif
            for (int i = 0; i < methods.Length; i++)
                if (methods[i].Name.StartsWith("test")) {
#if DEBUG
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine(">\tRunning the '{0}' method:", methods[i].Name);
                    Console.ForegroundColor = previousColor;
#endif
                    methods[i].Invoke(obj, null);
                    Test test = obj as Test;
                    if (!test.Success)
                        errorsFound[methods[i].Name] = new int[] { test.ExpectedErrors, test.ToError - test.FromError };
                    n++;
                }
#if DEBUG
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("> {0} tests of the '{1}' class executed successfully.\n", n, klass.Name);
            Console.ForegroundColor = previousColor;
#endif
            return n;
        }
private static int test ( Type klass , IDictionary < string , int [ ] > errorsFound ) { object obj = klass . GetConstructor ( new Type [ 0 ] ) . Invoke ( null ) ; MethodInfo [ ] methods = klass . GetMethods ( ) ; int n = 0 ; if DEBUG ConsoleColor previousColor = Console . ForegroundColor ; Console . ForegroundColor = ConsoleColor . Blue ; Console . WriteLine ( " " , klass . Name ) ; endif for ( int i = 0 ; i < methods . Length ; i ++ ) if ( methods [ i ] . Name . StartsWith ( " " ) ) { if DEBUG Console . ForegroundColor = ConsoleColor . Blue ; Console . WriteLine ( " \t " , methods [ i ] . Name ) ; Console . ForegroundColor = previousColor ; endif methods [ i ] . Invoke ( obj , null ) ; Test test = obj as Test ; if ( ! test . Success ) errorsFound [ methods [ i ] . Name ] = new int [ ] { test . ExpectedErrors , test . ToError - test . FromError } ; n ++ ; } if DEBUG Console . ForegroundColor = ConsoleColor . Blue ; Console . WriteLine ( " \n " , n , klass . Name ) ; Console . ForegroundColor = previousColor ; endif return n ; }
To run tests by means of introspection.
To run tests by means of introspection .
klass
Type
The class where testing methods are placed
The class where testing methods are placed
errorsFound
IDictionary<string, int[]>
The list of errors. Key=methodName, Value=[expectedErrors, errorsFound]
The list of errors . Key = methodName Value = [ expectedErrors errorsFound ]