-
Notifications
You must be signed in to change notification settings - Fork 325
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
Add enhancement: trx logger can take logfile parameter #282
Conversation
#endregion | ||
|
||
/// <summary> | ||
/// Gets the directory under which trx file should be saved. | ||
/// </summary> | ||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] | ||
public static string TrxFileDirectory | ||
public static string TrxFileDirectory //TODO: Rename to TestResultsDirectory?? |
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.
TestResultsDirectory makes sense. We will save test results attachments to TestResultsDirectory. After adding logfile parameter, TestResultsDirectory won't be always TrxFileDirectory.
@smadala do we need an e2e test for this? Or better our test.cmd can probably dogfood this :-) |
/// <param name="testRunDirectory">Test Run Directory</param> | ||
public void Initialize(TestLoggerEvents events, string testRunDirectory) | ||
/// <inheritdoc/> | ||
public void Initialize(TestLoggerEvents events, string testResultsDirPath) |
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.
When will this method get called?
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.
There is overloaded method, which calls it.
{ | ||
if (this.parametersDictionary != null && this.parametersDictionary.ContainsKey(LogFileParameterKey) && !string.IsNullOrWhiteSpace(this.parametersDictionary[LogFileParameterKey])) | ||
{ | ||
this.SetTrxFilePathFromParameters(); |
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.
Should we inline these methods. Some common code like creating a results directory could get combined.
@@ -454,6 +450,41 @@ private void HandleSkippedTest(ObjectModel.TestResult rsTestResult) | |||
this.AddRunLevelInformationalMessage(message); | |||
} | |||
|
|||
private void DeriveTrxFilePath() | |||
{ | |||
if (this.parametersDictionary != null && this.parametersDictionary.ContainsKey(LogFileParameterKey) && !string.IsNullOrWhiteSpace(this.parametersDictionary[LogFileParameterKey])) |
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.
Consider using Dictionary.TryGetValue. Use the value obtained for further checks instead of multiple dictionary lookups.
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.
make sense, made changes.
private void SetDefaultTrxFilePath() | ||
{ | ||
// save the trx file to testResultsDirectory | ||
if (Directory.Exists(TrxFileDirectory) == false) |
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.
It is confusing to use TrxFileDirectory in one case and derive the directory in the other.
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.
Renamed it to testResultsDirPath.
#endregion | ||
|
||
#region Fields | ||
|
||
|
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.
Suggestion: Remove extra lines.
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.
removed.
@smadala Make sure to verify that subsequent test runs with same value of |
We should fix #244 (for ubuntu) in this PR if possible. |
@harshjain2 Tested the scenario. It is overwriting. |
@@ -234,7 +234,7 @@ | |||
<data name="EnableLoggersArgumentHelp" xml:space="preserve"> | |||
<value>--logger|/logger:<Logger Uri/FriendlyName> | |||
Specify a logger for test results. For example, to log results into a | |||
Visual Studio Test Results File (TRX) use /logger:trx. | |||
Visual Studio Test Results File (TRX) use /logger:trx [;Logfile=<path to log file> [;Overwrite=<Defaults to "true">]] |
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.
Should we be specific? LogFile
can be absolute path or relative path? What does overwrite do?
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.
+1
this.InvokeVsTest(arguments); | ||
|
||
arguments = PrepareArguments(this.GetSampleTestAssembly(), this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue); | ||
arguments = string.Concat(arguments, $" /logger:\"trx;LogFileName={trxFileName}\""); |
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.
I believe order should be reverse.
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.
Done.
@@ -40,6 +40,7 @@ $env:TP_TOOLS_DIR = Join-Path $env:TP_ROOT_DIR "tools" | |||
$env:TP_PACKAGES_DIR = Join-Path $env:TP_ROOT_DIR "packages" | |||
$env:TP_OUT_DIR = Join-Path $env:TP_ROOT_DIR "artifacts" | |||
|
|||
|
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.
remove
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.
Done.
@@ -234,7 +234,9 @@ | |||
<data name="EnableLoggersArgumentHelp" xml:space="preserve"> | |||
<value>--logger|/logger:<Logger Uri/FriendlyName> | |||
Specify a logger for test results. For example, to log results into a | |||
Visual Studio Test Results File (TRX) use /logger:trx. | |||
Visual Studio Test Results File (TRX) use /logger:trx [;LogFileName=<Defaults to unique file name>] |
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.
May be just calling FileName
suffices instead of LogFileName
. @pvlakshm
TestLoggerManager.Instance.AddLogger(new Uri("test-logger-with-parameter://logger"), new Dictionary<string, string>()); | ||
Assert.IsNotNull(ValidLoggerWithParameters.parameters, "parameters not getting passed"); | ||
Assert.IsTrue(ValidLoggerWithParameters.parameters.ContainsKey(DefaultLoggerParameterNames.TestRunDirectory), $"{DefaultLoggerParameterNames.TestRunDirectory} not added to parameters"); | ||
Assert.IsFalse(string.IsNullOrWhiteSpace(ValidLoggerWithParameters.parameters[DefaultLoggerParameterNames.TestRunDirectory]), $"parameter {DefaultLoggerParameterNames.TestRunDirectory} should not be null, empty or whitespace"); |
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.
indent
👍 |
Edit: