コード例 #1
0
ファイル: RandomTestRunner.cs プロジェクト: schvila/endurance
        public void Run(TestedMethods methods, int minutes, System.IO.TextWriter writer)
        {
            _writer       = writer;
            _methods      = methods;
            _testDuration = (long)minutes * 60_000;
            _testMax      = _methods.Methods.Count;
            Stopwatch testDuration = Stopwatch.StartNew();
            Random    random       = new Random();

            while (testDuration.ElapsedMilliseconds < _testDuration)
            {
                InvokeNextTest(random);
            }
        }
コード例 #2
0
        public void Run(TestedMethods methods, int minutes, System.IO.TextWriter writer)
        {
            _methods = methods;
            Stopwatch methodSw = new Stopwatch();

            foreach (var testMethod in _methods.Methods)
            {
                methodSw.Restart();
                testMethod.Invoke(_durationOnly? null: writer);
                testMethod.Duration = methodSw.Elapsed.TotalMilliseconds;
                if (!_durationOnly)
                {
                    testMethod.Share += testMethod.Duration;
                    testMethod.TimesExecuted++;
                    Console.WriteLine(testMethod.ToShortDurationString(_methods.TestNameWidth));
                }
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: schvila/endurance
        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();
            }
        }