static void Main(string[] args) { Console.Write("\n Demonstrating Robust Test Loader"); Console.Write("\n ==================================\n"); DllLoaderExec loader = new DllLoaderExec(); if (args.Length > 0) { DllLoaderExec.testersLocation = args[0]; } else { DllLoaderExec.testersLocation = loader.GuessTestersParentDir() + "/Testers"; } // convert testers relative path to absolute path DllLoaderExec.testersLocation = Path.GetFullPath(DllLoaderExec.testersLocation); Console.Write("\n Loading Test Modules from:\n {0}\n", DllLoaderExec.testersLocation); // run load and tests string result = loader.loadAndExerciseTesters(); Console.Write("\n\n {0}", result); Console.Write("\n\n"); }
/*----< do tests after dll files received >--------------------*/ void filesReceived(Msg msg) { // create a new thread for mock building Thread testThrd = new Thread( () => { // parse test request TestRequest request = msg.argument.FromXml <TestRequest>(); if (request != null) // valid test request got { Console.Write("\n Parse test request successfully!"); foreach (TestElement te in request.tests) { string configName = te.buildConfig; string dllName = Path.GetFileNameWithoutExtension(configName) + ".dll"; // load dlls and test DllLoaderExec loader = new DllLoaderExec(); DllLoaderExec.testersLocation = Path.GetFullPath(TestHarnessEnvironment.storagePath); DllLoaderExec.testFileSpec = Path.GetFullPath(Path.Combine(TestHarnessEnvironment.storagePath, dllName)); Console.Write("\n Loading Test Module:\n {0}\n", DllLoaderExec.testFileSpec); // save the original output stream for Console TextWriter _old = Console.Out; // flush whatever was (if anything) in the log builder _LogBuilder = new StringWriter(); _LogBuilder.Flush(); Console.SetOut(_LogBuilder); // run load and tests string result = loader.loadAndExerciseTesters(); // set the Console output back to its original (StandardOutput that shows on the screen) Console.SetOut(_old); Console.Write("\n Test result: {0}\n", result); Console.Write("\n Printing Test Log:"); Console.Write(Log); string logName = saveTestLog(configName, Log); sendTestLog(logName); // send test logs to repo notifyClient(msg, configName, result); // notify client test result } } Console.Write("\n\n Test finished!\n"); } ); testThrd.Start(); }
//----< load assemblies from testersLocation and run their tests >----- public string loadAndExerciseTesters() { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromComponentLibFolder); try { DllLoaderExec loader = new DllLoaderExec(); // load each assembly found in testersLocation Assembly asm = Assembly.Load(File.ReadAllBytes(testFileSpec)); string fileName = Path.GetFileName(testFileSpec); Console.Write("\n loaded {0}\n", fileName); // exercise each tester found in assembly Type[] types = asm.GetTypes(); foreach (Type t in types) { // if type supports ITest interface then run test if (t.GetInterface("DllLoaderDemo.ITest", true) != null) { if (!loader.runSimulatedTest(t, asm)) { Console.Write("\n test {0} failed to run\n", t.ToString()); } } } } catch (Exception ex) { return(ex.Message); } return("Tests completed"); }