//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// runs one single test /// RunTest is not suited for very short methods, cause the overhead of invoking /// a method over the reflection mechanisme is too high /// </summary> /// <param name="tc">TestCase</param> /// <param name="m">Method to test</param> protected override void RunTest(TestCaseBase tc, MethodInfo m) { PerformanceTestCase testCase = (PerformanceTestCase)tc; Counter counter = Counter.Instance; PerformanceTestData td = new PerformanceTestData(); td.TestName = m.Name; // single invoke ulong startCount = counter.Count; m.Invoke(testCase, null); ulong endCount = counter.Count; td.SingleTime = (uint)Counter.GetElapsed(startCount, endCount); // multiple invoke startCount = counter.Count; for (uint i = 0; i < iterations; i++) { m.Invoke(testCase, null); } endCount = counter.Count; td.OverallTime = (uint)Counter.GetElapsed(startCount, endCount); td.TestNum = (uint)iterations; // raise event and pass testData if (testMethod != null) { testMethod(td); } }
/// <summary> /// executes the PerformanceTestCases /// </summary> /// <param name="testCases">list of performanceTestCases to test</param> public void Run(Type[] testCases) { TestCaseData tcd = new TestCaseData(); tcd.TestCaseNum = testCases.Length; // for every test case foreach (Type tct in testCases) { // get instance of Type TestCaseBase tc = (TestCaseBase)Activator.CreateInstance(tct); if (tc == null) { throw new TestException("Couldn't create instance of Type: " + tct.Name); } tcd.TestCaseName = tct.Name; tcd.MethodNum = tc.GetMethodsToTest().Count; if (beginTestCase != null) { beginTestCase(tcd); } // test every method foreach (MethodInfo m in tc.GetMethodsToTest()) { RunTest(tc, m); } if (finishedTestCase != null) { finishedTestCase(tcd); } } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// runs one single test /// </summary> /// <param name="tc">TestCase</param> /// <param name="m">Method to test</param> protected override void RunTest(TestCaseBase tc, MethodInfo m) { TestData td = new TestData(); td.MethodName = m.Name; td.Successful = true; try { m.Invoke(tc, new object[] {}); } catch (Exception e) { td.Successful = false; td.errorMessage = cleanMessage(e.InnerException.ToString()); } // raise event and pass testData if (testMethod != null) { testMethod(td); } }
/// <summary> /// runs one single test /// </summary> /// <param name="tc">TestCase</param> /// <param name="m">Method to test</param> protected abstract void RunTest(TestCaseBase tc, MethodInfo m);