/// <summary> /// Constructor uses the default test suit name /// </summary> protected TestClassBase() { if (!suiteNameCache.ContainsKey(this.GetType())) { suiteNameCache[this.GetType()] = staticTestSuiteName; } //switch test site while test running testSuiteName = suiteNameCache[this.GetType()]; testSite = ProtocolTestsManager.GetTestSite(testSuiteName); ptfTestNotify = ProtocolTestsManager.GetProtocolTestNotify(testSuiteName); }
/// <summary> /// Initializes the test suite base class with explicitly given test suite name. /// This method must be called by class initialize method in your test class. /// </summary> /// <param name="testContext">VSTS test context.</param> /// <param name="testSuiteName">The name of the test suite. The test site uses this name to find configuration files.</param> public static void Initialize(TestContext testContext, string testSuiteName) { executionStartTime = DateTime.Now; if (testContext == null) { throw new InvalidOperationException("TestContext should not be null in UnitTestClassBase."); } classCount++; staticTestSuiteName = testSuiteName; if (null == ProtocolTestsManager.GetTestSite(staticTestSuiteName)) { VstsTestContext vstsTestContext = new VstsTestContext(testContext); IConfigurationData config = ConfigurationDataProvider.GetConfigurationData( vstsTestContext.PtfconfigDir, testSuiteName); string testAssemblyName; if (isUseDefaultSuiteName) { testAssemblyName = testSuiteName; isUseDefaultSuiteName = false; } else { testAssemblyName = Assembly.GetCallingAssembly().GetName().Name; } ProtocolTestsManager.Initialize(config, vstsTestContext, testSuiteName, testAssemblyName); baseTestSite = ProtocolTestsManager.GetTestSite(testSuiteName); ITestSite site = ProtocolTestsManager.GetTestSite(testSuiteName); //registry all checkers RegisterChecker(site); } else { baseTestSite = ProtocolTestsManager.GetTestSite(testSuiteName); } /********************* Display expected runtime of the testsuite ********************** * Log expected execution time of the test suite in the log file * **************************************************************************************/ baseTestSite.Log.Add(LogEntryKind.Comment, "Expected execution time of the test suite (in seconds) is: " + baseTestSite.Properties.Get("ExpectedExecutionTime")); }
/// <summary> /// Cleans up the test suite. /// User must call this method in ClassCleanup method. /// </summary> public static void Cleanup() { classCount--; if (classCount == 0) { /********************* Display expected runtime of the testsuite ************************** * Calculates the actual time taken for the test suite execution and logs it in log file * ******************************************************************************************/ executionEndTime = DateTime.Now; double actualExecutionTime; actualExecutionTime = executionEndTime.Subtract(executionStartTime).TotalSeconds; baseTestSite.Log.Add(LogEntryKind.Comment, "Actual time taken for the test suite execution (in seconds) is: " + actualExecutionTime); ProtocolTestsManager.TestsRunCleanup(); } }