public ResultExporter() { string envDefaultConfigFile; string directory; SetupLogger(); log = LogManager.GetLogger(typeof(TestLinkAdaptor)); adaptor = new TestLinkAdaptor(log); defaultTlfa = new TestLinkFixtureAttribute(); envDefaultConfigFile = Environment.GetEnvironmentVariable(defaultConfigFileEnvironmentVariable); if (envDefaultConfigFile != null) { defaultConfigFile = envDefaultConfigFile; directory = ""; } else { directory = Directory.GetCurrentDirectory(); } defaultTlfa.ConfigFile = defaultConfigFile; if (!(defaultTlfa.ConsiderConfigFile(directory))) { log.Debug("Default config file " + defaultConfigFile + " not found!"); defaultTlfa = null; } }
/// <summary> /// get the specific project and associated plans for this TestLinkFixture /// </summary> /// <param name="tlfa"></param> /// <returns>a valid testplanID or 0 if testplan or project was not found</returns> private int GetProjectAndPlans(TestLinkFixtureAttribute tlfa) { // make sure proxy is right SetupProxy(tlfa); int testPlanId = 0; if ((currentProject == null) || (currentProject.name != tlfa.ProjectName)) { currentProject = null; plans = null; foreach (TestProject project in allProjects) { if (project.name == tlfa.ProjectName) { currentProject = project; plans = proxy.GetProjectTestPlans(project.id); break; } } if (currentProject == null) { return(0); } } // now that currentProject and plans are up to date foreach (TestPlan plan in plans) { if (plan.name == tlfa.TestPlan) { testPlanId = plan.id; break; } } return(testPlanId); }
private void SetupProxy(TestLinkFixtureAttribute tlfa) { if (serverUrl != tlfa.Url) { serverUrl = tlfa.Url; proxy = new TestLink(tlfa.DevKey, tlfa.Url); allProjects = proxy.GetProjects(); } }
/// <summary> /// after everything has been setup, record the actual result. /// </summary> /// <param name="result"></param> /// <param name="tlfa"></param> /// <param name="testPlanId"></param> /// <param name="TCaseId"></param> private void sendResultToTestlink(TestResult tcResult, TestLinkFixtureAttribute tlfa, int TCaseId) { TestCaseResultStatus status = TestCaseResultStatus.Blocked; StringBuilder notes = new StringBuilder(); notes.AppendLine(tcResult.Message); notes.AppendLine(currentTestOutput); switch (tcResult.ResultState) //RunState) { case ResultState.NotRunnable: status = TestCaseResultStatus.Blocked; break; case ResultState.Skipped: status = TestCaseResultStatus.Blocked; notes.AppendLine("++++ SKIPPED +++"); break; case ResultState.Ignored: status = TestCaseResultStatus.Blocked; notes.AppendLine("++++ IGNORED +++"); break; case ResultState.Success: status = TestCaseResultStatus.Pass; break; case ResultState.Failure: status = TestCaseResultStatus.Fail; break; case ResultState.Error: status = TestCaseResultStatus.Fail; break; } GeneralResult result = adaptor.RecordTheResult(TCaseId, status, notes.ToString()); if (result.status != true) { Console.WriteLine("Failed to export Result. Testlink reported: '{0}'", result.message); log.Warning(string.Format("Failed to export Result. Testlink reported: '{0}'", result.message)); } else { log.Info( string.Format("Reported Result (TCName=\"{0}\", TestPlan=\"{1}\", Status=\"{2}\").", tcResult.Name, tlfa.TestPlan, tcResult.ResultState.ToString())); } }
/// <summary> /// export the result of the run to TestLink. As a sideeffect, this may create a test case /// </summary> /// <param name="data"></param> public void ReportResult(Gallio.Runner.Reports.Schema.TestStepRun data) { try { TestLinkFixtureAttribute tlfa = getFixture(data.Step.FullName); if (tlfa == null) { Debug.WriteLine(string.Format("Failed to find testlinkfixture of name {0}", data.Step.FullName)); Console.Error.WriteLine("Failed to find testlinkfixture of name {0}", data.Step.FullName); adaptor.ConnectionData = null; return; } adaptor.ConnectionData = tlfa; //Debug.WriteLine(string.Format("new Testlink({0}, {1}", tlfa.DevKey, tlfa.Url)); string TestName = data.Step.Name; // Console.WriteLine(TestName); if (adaptor.ConnectionValid) { int tcid = adaptor.GetTestCaseId(TestName); if (tcid > 0) { //Console.Write("1"); recordResult(data, tcid); } else { Console.WriteLine("Could not find test case named '{0}'", TestName); } } else { Console.WriteLine(" -- Failed to export {0} --", TestName); } } catch (TestLinkException tlex) { Debug.WriteLine(tlex.Message); Console.WriteLine(tlex.Message); } catch (Exception ex) { Console.WriteLine("Exception occurred in TestLinkAddOn"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
/// <summary> /// we have a /// </summary> /// <param name="fixtureName"></param> /// <param name="path"></param> public void RetrieveTestFixture(string assemblyName, string path) { Assembly target = Assembly.LoadFile(path); Type[] allTypes = target.GetExportedTypes(); foreach (Type t in allTypes) { Debug.WriteLine(string.Format("Examining Type {0}", t.FullName)); foreach (System.Attribute attribute in t.GetCustomAttributes(typeof(TestLinkFixtureAttribute), false)) { TestLinkFixtureAttribute tlfa = attribute as TestLinkFixtureAttribute; if (tlfa != null) { string testStepName = string.Format("{0}/{1}", assemblyName, t.Name.Replace('.', '/')); fixtures.Add(testStepName, tlfa); } } } }
/// <summary> /// load the dll and extract the testfixture attribute from each class /// </summary> /// <param name="path"></param> private void extractTestFixtureAttribute(string path) { // assembly loading requires an absolute path if (Path.IsPathRooted(path) == false) { DirectoryInfo di = new DirectoryInfo("."); path = Path.Combine(di.FullName, path); } log.Debug(string.Format("Loading assembly '{0}'", path)); Assembly target = Assembly.LoadFile(path); Type[] allTypes = target.GetExportedTypes(); foreach (Type t in allTypes) { log.Debug(string.Format("Examining Type {0}", t.FullName)); foreach (System.Attribute attribute in t.GetCustomAttributes(typeof(TestLinkFixtureAttribute), false)) { TestLinkFixtureAttribute tlfa = attribute as TestLinkFixtureAttribute; if (tlfa != null) { tlfa.ConsiderConfigFile(Path.GetDirectoryName(path)); // trigger the attribute to look for a config file which may overload individual items log.Info(string.Format("Found fixture attribute for test fixture: {0}", t.FullName)); if (fixtures.ContainsKey(t.FullName)) { fixtures[t.FullName] = tlfa; } else { fixtures.Add(t.FullName, tlfa); } } } } }
/// <summary> /// after everything has been setup, record the actual result. /// </summary> /// <param name="result"></param> /// <param name="tlfa"></param> /// <param name="testPlanId"></param> /// <param name="TCaseId"></param> private void sendResultToTestlink(TestResult tcResult , TestLinkFixtureAttribute tlfa, string testCaseName) { TestCaseResultStatus status = TestCaseResultStatus.Blocked; StringBuilder notes = new StringBuilder(); notes.AppendLine(tcResult.Message); notes.AppendLine(currentTestOutput); switch (tcResult.ResultState) //RunState) { case ResultState.NotRunnable: status = TestCaseResultStatus.Blocked; break; case ResultState.Skipped: status = TestCaseResultStatus.Blocked; notes.AppendLine ("++++ SKIPPED +++"); break; case ResultState.Ignored: status = TestCaseResultStatus.Blocked; notes.AppendLine("++++ IGNORED +++"); break; case ResultState.Success: status = TestCaseResultStatus.Pass; break; case ResultState.Failure: status = TestCaseResultStatus.Fail; break; case ResultState.Error: status = TestCaseResultStatus.Fail; break; } GeneralResult result = adaptor.RecordTheResult(testCaseName, tlfa.TestSuite, status, notes.ToString()); if (result.status != true) { log.WarnFormat(string.Format("Failed to export Result. Testlink reported: '{0}'", result.message)); } else log.Info( string.Format("Reported Result (TCName=\"{0}\", TestPlan=\"{1}\", Status=\"{2}\").", tcResult.Name, tlfa.TestPlan, tcResult.ResultState.ToString())); }
private TestLinkConnectionData GetConnectionData(TestLinkFixtureAttribute tlfa) { return new TestLinkConnectionData(tlfa.Url, tlfa.DevKey, tlfa.UserId); }
public ResultExporter() { string envDefaultConfigFile; string directory; SetupLogger(); log = LogManager.GetLogger(typeof(TestLinkAdaptor)); adaptor = new TestLinkAdaptor(log); defaultTlfa = new TestLinkFixtureAttribute(); envDefaultConfigFile = Environment.GetEnvironmentVariable(defaultConfigFileEnvironmentVariable); if (envDefaultConfigFile != null) { defaultConfigFile = envDefaultConfigFile; directory = ""; } else { directory = Directory.GetCurrentDirectory(); } defaultTlfa.ConfigFile = defaultConfigFile; if (!(defaultTlfa.ConsiderConfigFile(directory))) { log.Debug("Default config file " + defaultConfigFile + " not found!"); defaultTlfa = null; } }
/// <summary> /// load the dll and extract the testfixture attribute from each class /// </summary> /// <param name="path"></param> private void extractTestFixtureAttribute(string path) { // assembly loading requires an absolute path if (Path.IsPathRooted(path) == false) { DirectoryInfo di = new DirectoryInfo("."); path = Path.Combine(di.FullName, path); } log.Debug(string.Format("Loading assembly '{0}'", path)); Assembly target = Assembly.LoadFile(path); Type[] allTypes = target.GetExportedTypes(); foreach (Type t in allTypes) { log.Debug(string.Format("Examining Type {0}", t.FullName)); TestLinkFixtureAttribute tlfa = null; foreach (System.Attribute attribute in t.GetCustomAttributes(typeof(TestLinkFixtureAttribute), false)) { tlfa = attribute as TestLinkFixtureAttribute; } if (tlfa == null) { if (defaultTlfa != null) { tlfa = (TestLinkFixtureAttribute)defaultTlfa.Clone(); log.DebugFormat("Using default config " + defaultConfigFile + " file for test fixture: {0}", t.FullName); } else { log.ErrorFormat("Unable to export results for {0}: No default config file (" + defaultConfigFile + ") available!", t.FullName); } } if (tlfa != null) { if (!tlfa.ConsiderConfigFile(Path.GetDirectoryName(path))) { tlfa.ConfigFile = defaultConfigFile; /* try again with default config file */ tlfa.ConsiderConfigFile(Path.GetDirectoryName(path)); } log.DebugFormat("Found fixture attribute for test fixture: {0}", t.FullName); try { tlfa.Validate(); if (fixtures.ContainsKey(t.FullName)) { fixtures[t.FullName] = tlfa; } else { fixtures.Add(t.FullName, tlfa); } } catch (Exception e) { log.ErrorFormat("Unable to export results for {0}: {1}", t.FullName, e.Message); } } } }
private TestLinkConnectionData GetConnectionData(TestLinkFixtureAttribute tlfa) { return(new TestLinkConnectionData(tlfa.Url, tlfa.DevKey, tlfa.UserId)); }