示例#1
0
        public void Run(TestedMethods methods, int minutes, System.IO.TextWriter writer)
        {
            _writer = writer;
            //
            var allTestsRunner = new AllTestsRunner(true);

            allTestsRunner.Run(methods, minutes, _writer);
            _methods      = methods;
            _testDuration = (long)minutes * 60_000;
            _testMax      = _methods.Methods.Count;
            EvaluateProbabilities();
            Stopwatch testDuration = Stopwatch.StartNew();

            while (testDuration.ElapsedMilliseconds < _testDuration)
            {
                InvokeNextTest();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            //TestConsoleOut();
            //Console.ReadLine();
            //return;
            if (args.Length < 3)
            {
                ReportUsage();
                return;
            }
            CmdLine cmdLine = new CmdLine(args);

            if (string.IsNullOrEmpty(cmdLine.AssemblyPathName) || cmdLine.Minutes == 0)
            {
                ReportUsage();
                return;
            }
            System.IO.TextWriter writer = Console.Out;

            if (!File.Exists(cmdLine.AssemblyPathName))
            {
                Console.WriteLine($"Assembly file not found: '{cmdLine.AssemblyPathName}'");
                Console.ReadLine();
                return;
            }
            try
            {
                if (!string.IsNullOrEmpty(cmdLine.OutFileName))
                {
                    writer = GetFileWriter(cmdLine.OutFileName);
                }
                TestedMethods testedMethods = new TestedMethods(cmdLine.AssemblyPathName);
                Console.WriteLine($"Methods to test:  {testedMethods.Methods.Count}");
                CmdLine.TestTypes actualTest = cmdLine.TestType;
                if (testedMethods.Methods.Count == 1 && actualTest == CmdLine.TestTypes.DurationAdjusted)
                {
                    actualTest = CmdLine.TestTypes.Random;
                }


                ITestRunner runner = null;
                switch (actualTest)
                {
                case CmdLine.TestTypes.Random:
                    runner = new RandomTestRunner();
                    break;

                case CmdLine.TestTypes.All:
                    runner = new AllTestsRunner();
                    break;

                case CmdLine.TestTypes.DurationAdjusted:
                    runner = new DurationAdjustedTestRunner();
                    break;

                default:
                    Console.WriteLine("UNKNOWN test runner");
                    break;
                }

                if (runner != null)
                {
                    runner.Run(testedMethods, cmdLine.Minutes, writer);
                    Console.WriteLine($"{Environment.NewLine}---Test statistics---{Environment.NewLine}");

                    testedMethods.SimpleReport();
                    Console.WriteLine($"{Environment.NewLine}----------------------------------{Environment.NewLine}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Test Failed: {Environment.NewLine}{ex.ToString()}");
            }
            finally
            {
                if (writer is StreamWriter sw)
                {
                    sw.Dispose();
                }

                Console.WriteLine("*** Test finished press any key...");
                Console.ReadLine();
            }
        }