-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trx Logger Fixes #1710
Trx Logger Fixes #1710
Changes from 3 commits
4a591ad
693815d
51d33ff
3803f73
3059723
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,72 +282,74 @@ public void TestResultHandler(object sender, ObjectModel.Logging.TestResultEvent | |
/// </param> | ||
public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) | ||
{ | ||
if (this.testRun != null) | ||
{ | ||
XmlPersistence helper = new XmlPersistence(); | ||
XmlTestStoreParameters parameters = XmlTestStoreParameters.GetParameters(); | ||
XmlElement rootElement = helper.CreateRootElement("TestRun"); | ||
// Create test run | ||
// If abort occurs there is no call to TestResultHandler which results in testRun not created. | ||
if (this.testRun == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Add UTs for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UT added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mention this happens when first batch itself aborts |
||
CreateTestRun(); | ||
|
||
// Save runId/username/creation time etc. | ||
this.testRun.Finished = DateTime.UtcNow; | ||
helper.SaveSingleFields(rootElement, this.testRun, parameters); | ||
XmlPersistence helper = new XmlPersistence(); | ||
XmlTestStoreParameters parameters = XmlTestStoreParameters.GetParameters(); | ||
XmlElement rootElement = helper.CreateRootElement("TestRun"); | ||
|
||
// Save test settings | ||
helper.SaveObject(this.testRun.RunConfiguration, rootElement, "TestSettings", parameters); | ||
// Save runId/username/creation time etc. | ||
this.testRun.Finished = DateTime.UtcNow; | ||
helper.SaveSingleFields(rootElement, this.testRun, parameters); | ||
|
||
// Save test results | ||
helper.SaveIEnumerable(this.results.Values, rootElement, "Results", ".", null, parameters); | ||
// Save test settings | ||
helper.SaveObject(this.testRun.RunConfiguration, rootElement, "TestSettings", parameters); | ||
|
||
// Save test definitions | ||
helper.SaveIEnumerable(this.testElements.Values, rootElement, "TestDefinitions", ".", null, parameters); | ||
// Save test results | ||
helper.SaveIEnumerable(this.results.Values, rootElement, "Results", ".", null, parameters); | ||
|
||
// Save test entries | ||
helper.SaveIEnumerable(this.entries.Values, rootElement, "TestEntries", ".", "TestEntry", parameters); | ||
// Save test definitions | ||
helper.SaveIEnumerable(this.testElements.Values, rootElement, "TestDefinitions", ".", null, parameters); | ||
|
||
// Save default categories | ||
List<TestListCategory> categories = new List<TestListCategory>(); | ||
categories.Add(TestListCategory.UncategorizedResults); | ||
categories.Add(TestListCategory.AllResults); | ||
helper.SaveList<TestListCategory>(categories, rootElement, "TestLists", ".", "TestList", parameters); | ||
// Save test entries | ||
helper.SaveIEnumerable(this.entries.Values, rootElement, "TestEntries", ".", "TestEntry", parameters); | ||
|
||
// Save summary | ||
if (this.testRunOutcome == TrxLoggerObjectModel.TestOutcome.Passed) | ||
{ | ||
this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Completed; | ||
} | ||
// Save default categories | ||
List<TestListCategory> categories = new List<TestListCategory>(); | ||
categories.Add(TestListCategory.UncategorizedResults); | ||
categories.Add(TestListCategory.AllResults); | ||
helper.SaveList<TestListCategory>(categories, rootElement, "TestLists", ".", "TestList", parameters); | ||
|
||
List<string> errorMessages = new List<string>(); | ||
List<CollectorDataEntry> collectorEntries = Converter.ToCollectionEntries(e.AttachmentSets, this.testRun, this.testResultsDirPath); | ||
IList<String> resultFiles = Converter.ToResultFiles(e.AttachmentSets, this.testRun, this.testResultsDirPath, errorMessages); | ||
// Save summary | ||
if (this.testRunOutcome == TrxLoggerObjectModel.TestOutcome.Passed) | ||
{ | ||
this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Completed; | ||
} | ||
|
||
if (errorMessages.Count > 0) | ||
List<string> errorMessages = new List<string>(); | ||
List<CollectorDataEntry> collectorEntries = Converter.ToCollectionEntries(e.AttachmentSets, this.testRun, this.testResultsDirPath); | ||
IList<String> resultFiles = Converter.ToResultFiles(e.AttachmentSets, this.testRun, this.testResultsDirPath, errorMessages); | ||
|
||
if (errorMessages.Count > 0) | ||
{ | ||
// Got some errors while attaching files, report them and set the outcome of testrun to be Error... | ||
this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Error; | ||
foreach (string msg in errorMessages) | ||
{ | ||
// Got some errors while attaching files, report them and set the outcome of testrun to be Error... | ||
this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Error; | ||
foreach (string msg in errorMessages) | ||
{ | ||
RunInfo runMessage = new RunInfo(msg, null, Environment.MachineName, TrxLoggerObjectModel.TestOutcome.Error); | ||
this.runLevelErrorsAndWarnings.Add(runMessage); | ||
} | ||
RunInfo runMessage = new RunInfo(msg, null, Environment.MachineName, TrxLoggerObjectModel.TestOutcome.Error); | ||
this.runLevelErrorsAndWarnings.Add(runMessage); | ||
} | ||
|
||
TestRunSummary runSummary = new TestRunSummary( | ||
this.totalTests, | ||
this.passTests + this.failTests, | ||
this.passTests, | ||
this.failTests, | ||
this.testRunOutcome, | ||
this.runLevelErrorsAndWarnings, | ||
this.runLevelStdOut.ToString(), | ||
resultFiles, | ||
collectorEntries); | ||
|
||
helper.SaveObject(runSummary, rootElement, "ResultSummary", parameters); | ||
|
||
//Save results to Trx file | ||
this.DeriveTrxFilePath(); | ||
this.PopulateTrxFile(this.trxFilePath, rootElement); | ||
} | ||
|
||
TestRunSummary runSummary = new TestRunSummary( | ||
this.totalTests, | ||
this.passTests + this.failTests, | ||
this.passTests, | ||
this.failTests, | ||
this.testRunOutcome, | ||
this.runLevelErrorsAndWarnings, | ||
this.runLevelStdOut.ToString(), | ||
resultFiles, | ||
collectorEntries); | ||
|
||
helper.SaveObject(runSummary, rootElement, "ResultSummary", parameters); | ||
|
||
//Save results to Trx file | ||
this.DeriveTrxFilePath(); | ||
this.PopulateTrxFile(this.trxFilePath, rootElement); | ||
} | ||
|
||
/// <summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,15 +461,26 @@ private static CollectorDataEntry ToCollectorEntry(ObjectModel.AttachmentSet att | |
|
||
// copy the source file to the target location | ||
string targetFileName = FileHelper.GetNextIterationFileName(targetDirectory, Path.GetFileName(sourceFile), false); | ||
CopyFile(sourceFile, targetFileName); | ||
|
||
// Add the target file name to the collector files list. | ||
// (Trx viewer automatically adds In\ to the collected file. | ||
string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); | ||
Uri sourceFileUri = new Uri(fileName, UriKind.Relative); | ||
TrxObjectModel.UriDataAttachment dataAttachment = new TrxObjectModel.UriDataAttachment(uriDataAttachment.Description, sourceFileUri); | ||
try | ||
{ | ||
CopyFile(sourceFile, targetFileName); | ||
|
||
// Add the target file name to the collector files list. | ||
// (Trx viewer automatically adds In\ to the collected file. | ||
string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); | ||
Uri sourceFileUri = new Uri(fileName, UriKind.Relative); | ||
TrxObjectModel.UriDataAttachment dataAttachment = new TrxObjectModel.UriDataAttachment(uriDataAttachment.Description, sourceFileUri); | ||
|
||
uriDataAttachments.Add(dataAttachment); | ||
uriDataAttachments.Add(dataAttachment); | ||
} | ||
catch(Exception ex) | ||
{ | ||
if (ObjectModel.EqtTrace.IsErrorEnabled) | ||
{ | ||
ObjectModel.EqtTrace.Error("Trxlogger: ToCollectorEntry: " + ex); | ||
} | ||
} | ||
} | ||
|
||
return new CollectorDataEntry( | ||
|
@@ -509,15 +520,25 @@ private static IList<string> ToResultFiles(ObjectModel.AttachmentSet attachmentS | |
|
||
string sourceFile = uriDataAttachment.Uri.LocalPath; | ||
Debug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); | ||
|
||
// copy the source file to the target location | ||
string targetFileName = FileHelper.GetNextIterationFileName(testResultDirectory, Path.GetFileName(sourceFile), false); | ||
CopyFile(sourceFile, targetFileName); | ||
|
||
// Add the target file name to the result files list. | ||
// (Trx viewer automatically adds In\<Guid> to the result file. | ||
string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); | ||
resultFiles.Add(fileName); | ||
try | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we hit any while validating? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to issue #1705 TRX Logger shouldn't fail if test result attachments are missing/Invalid. |
||
{ | ||
CopyFile(sourceFile, targetFileName); | ||
|
||
// Add the target file name to the result files list. | ||
// (Trx viewer automatically adds In\<Guid> to the result file. | ||
string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); | ||
resultFiles.Add(fileName); | ||
} | ||
catch(Exception ex) | ||
{ | ||
if (ObjectModel.EqtTrace.IsErrorEnabled) | ||
{ | ||
ObjectModel.EqtTrace.Error("Trxlogger: ToResultFiles: " + ex); | ||
} | ||
} | ||
} | ||
|
||
return resultFiles; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -515,6 +515,18 @@ public void TestResultHandlerShouldAddSingleTestEntryForOrderedTest() | |
Assert.AreEqual(this.testableTrxLogger.TestEntryCount, 1, "TestResultHandler is adding multiple test entries for ordered test."); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRunCompleteHandlerShouldReportFailedOutcomeIfTestRunIsAborted() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add check for attachments |
||
{ | ||
string message = "The information to test"; | ||
TestRunMessageEventArgs trme = new TestRunMessageEventArgs(TestMessageLevel.Error, message); | ||
this.testableTrxLogger.TestMessageHandler(new object(), trme); | ||
|
||
this.testableTrxLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero)); | ||
|
||
Assert.AreEqual(this.testableTrxLogger.TestResultOutcome, TrxLoggerObjectModel.TestOutcome.Failed); | ||
} | ||
|
||
[TestMethod] | ||
public void OutcomeOfRunWillBeFailIfAnyTestsFails() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain what scenario needs this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment