예제 #1
0
        public static void RunTestHelper(ITest test)
        {
            test.Result.Status = TestStatus.Pass;
            TestTimer timer = new TestTimer();

            try
            {
                timer.Start(test);
                test.TestMethod.Invoke(test.Fixture.Instance, null);
                timer.Stop();
            }
            catch (TargetInvocationException tie)
            {
                timer.Stop();
                Exception exp = tie.InnerException;
                test.Result.Status = TestStatus.Fail;
                test.Result.Message.AppendLine(exp.Message);
                test.Result.Message.Append("EXCEPTION TYPE: ");
                test.Result.Message.AppendLine(exp.GetType().FullName);
                test.Result.SetFilteredStackTrace(exp.StackTrace);
            }
            finally
            {
                timer.Stop();
            }
        }
        /// <summary>
        /// Runn the test.
        /// </summary>
        public void RunTest(ITest test)
        {
            TestTimer timer = new TestTimer();

            try
            {
                timer.Start(test);
                test.TestMethod.Invoke(test.Fixture.Instance, null);
                timer.Stop();
            }
            catch (TargetInvocationException tie)
            {
                timer.Stop();
                Type thrownExceptionType = tie.InnerException.GetType();
                test.Result.Message.AppendFormat("Expected Exception: {0}", ExceptionType.FullName);
                if (thrownExceptionType.Equals(ExceptionType) && (Message == null || tie.InnerException.Message == Message))
                {
                    test.Result.Status = TestStatus.Pass;
                    test.Result.Message.AppendLine(" was thrown.");
                }
                else
                {
                    test.Result.Status = TestStatus.Fail;
                    test.Result.Message.AppendLine(" was NOT thrown.");
                }
                test.Result.Message.Append("Message: ");
                test.Result.Message.AppendLine(tie.InnerException.Message);
                test.Result.Message.Append("Exception Type: ");
                test.Result.Message.AppendLine(thrownExceptionType.FullName);
                test.Result.SetFilteredStackTrace(tie.InnerException.StackTrace);
            }
            finally
            {
                timer.Stop();
                if (test.Result.Status == TestStatus.Untested)
                {
                    // No exception has been thrown.

                    test.Result.Status = TestStatus.Fail;
                    test.Result.Message.AppendFormat("Expected Exception: {0}", ExceptionType.FullName);
                    test.Result.Message.AppendLine(" was NOT thrown.");
                    SequenceManager sm = new SequenceManager(test.TestMethod);
                    if (sm.IsSourceAvailable())
                    {
                        test.Result.StackTrace = sm.GetStackTrace(0);
                    }
                }
            }
        }
예제 #3
0
        private void buttonStop_Click(object sender, EventArgs e)
        {
            Stopping = true;
            try
            {
                if (TestTimerMonitor.ThreadState == ThreadState.Running)
                {
                    TestTimerMonitor.Abort();
                }

                if (TestTimer.Enabled)
                {
                    TestTimer.Stop();
                }

                if (RunnerThread.ThreadState == ThreadState.Running)
                {
                    RunnerThread.Abort();
                }

                ChangeControlStatus(buttonRunTest, true);
                ChangeControlStatus(buttonStartDaemon, true);

                if (SeleniumChromeDriver != null)
                {
                    SeleniumChromeDriver.Quit();
                }
            }
            catch
            {
                // ignored
            }
        }
        public void OnShrink(FSharpList <object> args, FSharpFunc <FSharpList <object>, string> everyShrink)
        {
            TestTimer.Stop();
            RunnerImplementation.OnShrink(args, everyShrink);
            numberOfShrinks++;

            if (!isDetailedTraces)
            {
                if (isRunningTests && FsCheckRunnerConfig.TraceNumberOfRuns)
                {
                    isRunningTests = false;
                    FormattableString.Invariant($"Failed test: {latestNumTests} / {MaxTest}");
                }

                if (isRunningShrinks && FsCheckRunnerConfig.TraceNumberOfRuns)
                {
                    Trace(
                        FormattableString.Invariant(
                            $"Ran shrink: {numberOfShrinks} in {TestTimer.ElapsedMilliseconds:n0}ms"
                            )
                        );
                }

                isRunningShrinks = true;
            }

            TestTimer.Restart();
        }
예제 #5
0
        protected void CleanUp(string testFolder = DefaultRuntimeFolder)
        {
            Logger.Log(Level.Verbose, "Cleaning up test.");

            if (_enableRealtimeLogUpload)
            {
                if (TimerTask != null)
                {
                    TestTimer.Stop();
                    TimerTask.Dispose();
                    TimerTask = null;
                }

                // Wait for file upload task to complete
                Thread.Sleep(500);
            }

            string dir = Path.Combine(Directory.GetCurrentDirectory(), testFolder);

            try
            {
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
            }
            catch (IOException)
            {
                // do not fail if clean up is unsuccessful
            }
            catch (UnauthorizedAccessException)
            {
                // do not fail if clean up is unsuccessful
            }
        }
예제 #6
0
        protected void CleanUp(string testFolder = DefaultRuntimeFolder)
        {
            Console.WriteLine("Cleaning up test.");

            if (TimerTask != null)
            {
                TestTimer.Stop();
                TimerTask.Dispose();
                TimerTask = null;
            }

            // Wait for file upload task to complete
            Thread.Sleep(500);

            string dir = Path.Combine(Directory.GetCurrentDirectory(), testFolder);

            try
            {
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
            }
            catch (IOException)
            {
                // do not fail if clean up is unsuccessful
            }
        }
예제 #7
0
        public void StartNow_ExecutesEventImmediately()
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.StartNow(100000);
            timer.Stop();
            _numberOfExecutions.Should().Be(1);
        }
예제 #8
0
        public void SimulatePassageOfTime_Wait_ExecutesCorrectAmountOfEvents(int timeBetweenEvents, int timeToWait, int expectedAmountOfExecuted)
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(timeBetweenEvents);
            timer.SimulateTime(timeToWait);
            timer.Stop();

            _numberOfExecutions.Should().Be(expectedAmountOfExecuted);
        }
예제 #9
0
        public void SimulatePassageOfTime_WaitLessThanOneEvent_DoesNotExecuteEvent()
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(1000);
            timer.SimulateTime(999);
            timer.Stop();

            _numberOfExecutions.Should().Be(0);
        }
예제 #10
0
        public void SimulatePassageOfTime_WaitExactlyForOneEvent_ExecutesOneEvent()
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(1000);
            timer.SimulateTime(1000);
            timer.Stop();

            _numberOfExecutions.Should().Be(1);
        }
예제 #11
0
        public void StartNow_ExecutesFurtherEvents()
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.StartNow(1000);
            timer.SimulateTime(1000);
            timer.Stop();

            _numberOfExecutions.Should().Be(2);
        }
예제 #12
0
        /// <summary>
        /// Executes the inner test method, gathering the amount of time it takes to run.
        /// </summary>
        /// <returns>Returns information about the test run</returns>
        public override MethodResult Execute(object testClass)
        {
            TestTimer timer = new TestTimer();

            timer.Start();
            MethodResult methodResult = InnerCommand.Execute(testClass);
            timer.Stop();

            methodResult.ExecutionTime = timer.ElapsedMilliseconds / 1000.00;

            return methodResult;
        }
예제 #13
0
        public void SimulatePassageOfTime_WaitMoreThanOneEventButLessThanTwo_ExecutesOnesEvent(int timeBetweenEvents, int timeToWait)
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(timeBetweenEvents);
            timer.SimulateTime(timeToWait);
            timer.Stop();

            _numberOfExecutions.Should().Be(1);
        }
        /// <summary>
        /// This method is called by the test object to invoke the test.
        /// </summary>
        /// <param name="test">The calling test object.</param>
        public void RunTest(ITest test)
        {
            // TODO use an ITestSuiteBuilder, IFixtureBuilder and ITestBuilder instead of a builder factory
            // this would allow more granular builder definitions.
            test.Result.Status = TestStatus.Pass;
            TestTimer timer = new TestTimer();

            List <object[]> parameters = new List <object[]>();

            TestParametersAttribute[] tpas = test.TestMethod.GetCustomAttributes(
                typeof(TestParametersAttribute), false) as TestParametersAttribute[];
            if (tpas != null)
            {
                for (int i = 0; i < tpas.Length; i++)
                {
                    parameters.AddRange(tpas[i].GetParameters(test));
                }
            }

            timer.Start(test);
            for (int i = 0; i < parameters.Count; i++)
            {
                try
                {
                    test.TestMethod.Invoke(test.Fixture.Instance, parameters[i]);
                }
                catch (TargetInvocationException tie)
                {
                    Exception exp = tie.InnerException;
                    test.Result.Status = TestStatus.Fail;
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("Test run {0} failed with parameters: ", i + 1);
                    if (parameters[i] != null && parameters[i].Length > 0)
                    {
                        sb.Append(AssertionFailureMessage.FormatObjectForDisplay(parameters[i][0]));
                        for (int j = 1; j < parameters[i].Length; j++)
                        {
                            sb.AppendFormat(", {0}", AssertionFailureMessage.FormatObjectForDisplay(parameters[i][j]));
                        }
                    }
                    test.Result.Message.AppendLine(sb.ToString());
                    test.Result.Message.AppendLine(exp.Message);
                    test.Result.Message.Append("EXCEPTION TYPE: ");
                    test.Result.Message.AppendLine(exp.GetType().FullName);
                    if (test.Result.StackTrace == null)
                    {
                        test.Result.SetFilteredStackTrace(exp.StackTrace);
                    }
                }
            }
            timer.Stop();
        }
예제 #15
0
        /// <summary>
        /// Executes the inner test method, gathering the amount of time it takes to run.
        /// </summary>
        /// <returns>Returns information about the test run</returns>
        public override MethodResult Execute(object testClass)
        {
            TestTimer timer = new TestTimer();

            timer.Start();
            MethodResult methodResult = InnerCommand.Execute(testClass);

            timer.Stop();

            methodResult.ExecutionTime = timer.ElapsedMilliseconds / 1000.00;

            return(methodResult);
        }
예제 #16
0
        private void Stop()
        {
            finderSystem?.Stop();
            stopwatch.Stop();
            TestTimer.Stop();

            StopButton.Enabled             = false;
            splitContainer2.Panel2.Enabled = false;
            ClearUuIdTextButton.Enabled    = true;
            StartButton.Enabled            = true;

            TestTimeLeftText.Text = "00:00:00";
        }
예제 #17
0
 private void btnCommaxTest_Click(object sender, EventArgs e)
 {
     if (TestTimer.Enabled)
     {
         TestTimer.Stop();
         btnCommaxTest.Text = "시작";
     }
     else
     {
         int sec = 30; //30초;
         int.TryParse(txtCommaxSec.Text, out sec);
         TestTimer.Interval = sec * 1000;
         TestTimer.Start();
         btnCommaxTest.Text = "정지";
     }
 }
예제 #18
0
        public void NextElementIteration()
        {
            isAnswering = !isAnswering;

            timer.Stop();
            if (!isAnswering)
            {
                label.Text = MemoryTest.GetRow();
                timer.Start();
            }

            if (isAnswering)
            {
                textBox.Text = "";
            }

            textBox.Visible = isAnswering;
            label.Visible   = !isAnswering;
            timer.Visible   = !isAnswering;
        }
예제 #19
0
        private void TestTimer_Tick(object sender, EventArgs args)
        {
            var session = finderSystem.GetTestSession();

            if (DateTime.Now <= session.EndDateTime)
            {
                var timeLeft = session.EndDateTime.Value - DateTime.Now;
                TestTimeLeftText.Text = timeLeft.ToString(@"hh\:mm\:ss");

                if (timeLeft.TotalMinutes <= 5 && session.Duration.Value.TotalMinutes >= 5)
                {
                    TestTimeLeftText.ForeColor = Color.FromArgb(255, 36, 36);
                }
            }
            else
            {
                splitContainer2.Panel2.Enabled = false;
                TestTimer.Stop();
                MessageForm.Show("Время прохождения теста истекло. Советуем подождать, пока программа найдёт ответы, что бы сохранить их для других учеников", "Тест завершён", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #20
0
        private void buttonStartDaemon_Click(object sender, EventArgs e)
        {
            try
            {
                if (TestTimer.Enabled)
                {
                    TestTimer.Stop();
                }

                TestTimer.Tick -= Timer_Tick;
            }
            catch
            {
                // ignored
            }

            TestTimerInterval  = Convert.ToInt32(numericUpDownInterval.Value);
            TestTimer.Interval = TestTimerInterval * 60 * 1000;
            TestTimer.Tick    += Timer_Tick;
            TestTimer.Start();
            buttonRunTest_Click(sender, e);
            ChangeControlStatus(buttonStartDaemon, false);
        }
예제 #21
0
        public void OnArguments(
            int numTest, FSharpList <object> args, FSharpFunc <int, FSharpFunc <FSharpList <object>, string> > every)
        {
            TestTimer.Stop();
            RunnerImplementation.OnArguments(numTest, args, every);
            latestNumTests++;

            if (!isDetailedTraces)
            {
                if (FsCheckRunnerConfig.TraceNumberOfRuns)
                {
                    Trace(
                        FormattableString.Invariant(
                            $"Ran test: {latestNumTests} / {MaxTest} in {TestTimer.ElapsedMilliseconds:n0}ms"
                            )
                        );
                }

                isRunningTests = true;
            }

            TestTimer.Restart();
        }
예제 #22
0
        /// <summary>
        /// Run the test.
        /// </summary>
        public void RunTest(ITest test)
        {
            Type       fixtureType = test.Fixture.Instance.GetType();
            MethodInfo method      = test.TestMethod;

            DynamicMethod testMethod = GetTestMethod(fixtureType, method);

            TestTimer timer = new TestTimer();
            Dictionary <int, Exception> exceptionsThrown;
            TestDelegate testDelegate = testMethod.CreateDelegate(typeof(TestDelegate), test.Fixture.Instance) as TestDelegate;

            try
            {
                timer.Start(test);
                exceptionsThrown = testDelegate();
                timer.Stop();
            }
            catch (InvalidProgramException exp)
            {
                timer.Stop();
                throw new InvalidOperationException("Unable to catch thrown exceptions in test method.", exp);
            }
            finally
            {
                timer.Stop();
            }

            SequenceManager sm = new SequenceManager(test.TestMethod);
            int             expectedExceptionCount  = 0;
            int             unexpectedExpectedCount = 0;
            int             i = 0;

            foreach (KeyValuePair <int, Exception> exception in exceptionsThrown)
            {
                if (exception.Value != null)
                {
                    Type thrownExceptionType = exception.Value.GetType();
                    test.Result.Output.AppendFormat("[{0}] Expected Exception: {1}", i + 1, ExceptionType.FullName);
                    if (thrownExceptionType.Equals(ExceptionType))
                    {
                        expectedExceptionCount++;
                        test.Result.Output.AppendLine(" was thrown.");
                    }
                    else
                    {
                        // Get line offset from il instruction offset.
                        unexpectedExpectedCount++;
                        test.Result.Output.AppendLine(" was NOT thrown.");
                        test.Result.Output.Append("\tThrown Exception Was: ");
                        if (sm.IsSourceAvailable())
                        {
                            int    sequenceOffset = Math.Abs(Array.BinarySearch <int>(sm.Offsets, exception.Key));
                            string dynamicLine    = String.Format("   at {0}_TestMethod({1} )",
                                                                  test.TestMethod.Name, test.Fixture.FixtureType.Name);
                            string sourceLine = sm.GetStackTrace(sequenceOffset);
                            test.Result.Output.AppendLine(
                                exception.Value.ToString().Replace(dynamicLine, sourceLine));
                            if (test.Result.StackTrace == null)
                            {
                                test.Result.SetFilteredStackTrace(
                                    exception.Value.StackTrace.Replace(dynamicLine, sourceLine));
                            }
                        }
                        else
                        {
                            test.Result.Output.AppendLine(exception.Value.ToString());
                            if (test.Result.StackTrace == null)
                            {
                                test.Result.SetFilteredStackTrace(exception.Value.StackTrace);
                            }
                        }
                    }
                }
                else
                {
                    test.Result.Output.AppendFormat("[{0}] No exception was thrown.\n", i + 1);
                }
                i++;
            }

            if (test.Result.StackTrace == null && sm.IsSourceAvailable())
            {
                test.Result.StackTrace = sm.GetStackTrace(0);
            }

            int expectedNumberOfExceptions = (ExceptionCount == UseTestCount ? exceptionsThrown.Count : ExceptionCount);

            test.Result.Message.AppendFormat(ExpectedExceptionCountMessage,
                                             ExceptionType.FullName, expectedExceptionCount, exceptionsThrown.Count, expectedNumberOfExceptions,
                                             unexpectedExpectedCount, (unexpectedExpectedCount != 1 ? " was" : "s were"));
            if (expectedExceptionCount != expectedNumberOfExceptions || (FailOnOtherExceptions && unexpectedExpectedCount > 0))
            {
                test.Result.Status = TestStatus.Fail;
            }
            else
            {
                test.Result.Status = TestStatus.Pass;
            }
        }