示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            runTest = new RunTestDelegate(RunTest);

            Thread t = new Thread(Run);

            t.IsBackground = true;
            t.Start();
        }
 static void DoTest(RunTestDelegate f, string name)
 {
     var results = new List<TimeSpan>();
     for (int i = NUM_RUNS; i > 0; i--)
     {
         results.Add(RunTestParallelPreAlloc());
     }
     Console.WriteLine("{0}: Execution Time Average (ms): {1} ", name, results.Select(t => t.TotalMilliseconds).Average());
 }
示例#3
0
        // Run the specified test.  All hosting tests are expected to throw
        // ApplicationException on failure.  That's how failures are identified.
        public static int RunTest(RunTestDelegate rtd, string name, string owner, string[] args)
        {
            ApplicationException appex = null;

            _logFileWriter = File.CreateText(name + LOGEXT);

            Output(/* verboseonly = */ false, "Running {0} -- Owner: {1}", name, owner);

            try
            {
                // Parse the command line arguments for options generic to all hosting DRTs.
                ParseCommandLine(args);

                // Handle razzle specific stuff.
                HandleRazzle();

                // Run the test.
                rtd();
            }
            catch (ApplicationException exparam)
            {
                // Expect an ApplicationException to be thrown for all failures.
                appex = exparam;
            }

            // Write success or failure information to the console.
            if (appex != null)
            {
                Output(/* verboseonly = */ false, appex.ToString());
                Output(/* verboseonly = */ false, "{0} Test failed.", name);
            }
            else
            {
                Output(/* verboseonly = */ false, "{0} Test passed.", name);
            }

            // Return 0 on success and 1 on failure.
            return(appex == null ? 0 : 1);
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            runTest = new RunTestDelegate(RunTest);

            Thread t = new Thread(Run);
            t.IsBackground = true;
            t.Start();
        }
示例#5
0
        static IEnumerable <Test> QueueTests(Type @class, bool suppressCoverage)
        {
            var pre  = @class.GetMethods().SingleOrDefault(m => m.GetCustomAttribute <TestInitializeAttribute>() != null);
            var post = @class.GetMethods().SingleOrDefault(m => m.GetCustomAttribute <TestCleanupAttribute>() != null);

            var inst = Activator.CreateInstance(@class);

            foreach (var mtd in @class.GetMethods().Where(m => m.GetCustomAttribute <TestMethodAttribute>() != null))
            {
                var testName = @class.Name + "." + mtd.Name;

                RunTestDelegate run =
                    (out List <Covered> coverage, out string errorMessage) =>
                {
                    Task <List <Covered> > coverageTask = null;
                    if (!suppressCoverage)
                    {
                        coverageTask = CollectCoverageAsync(testName);
                    }

                    var       sw = new Stopwatch();
                    Exception failed;
                    Console.Write($"Running {testName} ");
                    sw.Start();
                    try
                    {
                        pre?.Invoke(inst, Empty);
                        mtd.Invoke(inst, Empty);
                        post?.Invoke(inst, Empty);
                        failed = null;
                    }
                    catch (Exception e)
                    {
                        failed = e;
                    }

                    if (coverageTask != null)
                    {
                        if (failed == null)
                        {
                            coverage = coverageTask.Result;
                        }
                        else
                        {
                            coverage = null;
                        }
                    }
                    else
                    {
                        coverage = null;
                    }
                    sw.Stop();

                    long workingSet;
                    using (var proc = Process.GetCurrentProcess())
                    {
                        workingSet = proc.WorkingSet64;
                    }

                    Console.Write($" ({sw.ElapsedMilliseconds:N0}ms, {workingSet:N0} bytes)... ");

                    if (failed == null)
                    {
                        Console.WriteLine("Passed");
                        errorMessage = null;
                        return(true);
                    }
                    else
                    {
                        Console.WriteLine("!!FAILED!!");
                        var exc = GetException(failed, 1);
                        Console.WriteLine(exc);
                        errorMessage = exc;
                        return(false);
                    }
                };

                yield return(new Test {
                    Name = testName, Run = run
                });
            }
        }