Skip to content
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

Merged
merged 15 commits into from
Dec 26, 2016
Merged

Add enhancement: trx logger can take logfile parameter #282

merged 15 commits into from
Dec 26, 2016

Conversation

smadala
Copy link
Contributor

@smadala smadala commented Dec 14, 2016

  • --loggerOutput option #243 Trx logger takes logfile parameter, ex:/logger:"trx;logfile=C:\pathto\test_results.trx"
  • Added tests for same

Edit:

  • logfilename parameter takes name of the filename(not path).
  • file will be create in test results directory.
  • ex: /logger:"trx;logfilename=test_results.trx"

@smadala smadala requested a review from codito December 14, 2016 12:51
#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??
Copy link
Contributor Author

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.

@codito
Copy link
Contributor

codito commented Dec 14, 2016

@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)
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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]))
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove extra lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@harshjain2
Copy link
Contributor

harshjain2 commented Dec 15, 2016

@smadala Make sure to verify that subsequent test runs with same value of logfile should override the previous trx logger file.

@codito
Copy link
Contributor

codito commented Dec 16, 2016

We should fix #244 (for ubuntu) in this PR if possible.

@smadala
Copy link
Contributor Author

smadala commented Dec 20, 2016

@harshjain2 Tested the scenario. It is overwriting.

@@ -234,7 +234,7 @@
<data name="EnableLoggersArgumentHelp" xml:space="preserve">
<value>--logger|/logger:&lt;Logger Uri/FriendlyName&gt;
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=&lt;path to log file&gt; [;Overwrite=&lt;Defaults to "true"&gt;]]
Copy link
Contributor

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?

Copy link
Contributor

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}\"");
Copy link
Contributor

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.

Copy link
Contributor Author

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"


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

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:&lt;Logger Uri/FriendlyName&gt;
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=&lt;Defaults to unique file name&gt;]
Copy link
Contributor

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

@codito
Copy link
Contributor

codito commented Dec 23, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants