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

Html logger #2103

Merged
merged 24 commits into from
Aug 29, 2019
Merged

Html logger #2103

merged 24 commits into from
Aug 29, 2019

Conversation

hvinett
Copy link
Contributor

@hvinett hvinett commented Jul 29, 2019

Description

Adding the html logger, which would output the test results in the html format.

Related issue

#2065

  • Add Unit Tests
  • Add docs for the public methods
  • Add exception handling
  • Add logging

Here is the draft html
image

@msftclas
Copy link

msftclas commented Jul 29, 2019

CLA assistant check
All CLA requirements met.

@hvinett hvinett changed the title Html logger [Draft] Html logger Jul 29, 2019
2. Added remaining unit tests
3. Removed redundant spaces.
@singhsarab
Copy link
Contributor

Remove this file


Refers to: src/Microsoft.TestPlatform.Extensions.HtmlLogger/html.html:1 in a5fe993. [](commit_id = a5fe993, deletion_comment = False)

@singhsarab
Copy link
Contributor

singhsarab commented Jul 31, 2019

// Copyright (c) Microsoft Corporation. All rights reserved.

Rename the file name of this file, make sure it is formatted correctly.
TestResult.cs

Also, put these files in a folder, name it ObjectModel


Refers to: src/Microsoft.TestPlatform.Extensions.HtmlLogger/Testresult.cs:1 in a5fe993. [](commit_id = a5fe993, deletion_comment = False)

});
}

/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some useful summary for the tests, repeating what's already there in the name of the test is not advisable.

ex.ToString());
ConsoleOutput.Instance.Error(false, string.Concat(HtmlResource.HtmlLoggerError), ex.Message);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests for these

{
DisplayName = "def",
ErrorMessage = "error message",
ErrorStackTrace = "Error stack trace",
Copy link
Contributor

Choose a reason for hiding this comment

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

Incomplete test

@@ -132,5 +132,11 @@ public string[] GetFiles(string path, string searchPattern, SearchOption searchO
{
return Directory.GetFiles(path, searchPattern, searchOption);
}

/// <inheritdoc/>
public void Delete(string path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change this to TryDelete with bool return, In case file does not exists this API will throw.

/// </summary>
/// <param name="duration"></param>
/// <returns></returns>
internal string GetFormattedDurationString(TimeSpan duration)
Copy link
Contributor

Choose a reason for hiding this comment

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

GetFormattedDurationString [](start = 24, length = 26)

make it private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i want to test the GetFormattedDurationString function.


TestResultsDirPath = testResultsDirPath;
TestRunDetails = new TestRunDetails();
Results = new ConcurrentDictionary<Guid, ObjectModel.TestResult>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Results [](start = 12, length = 7)

do we need concurrent dictionaries, I'm not sure if multiple threads are trying to add to results.

@hvinett
Copy link
Contributor Author

hvinett commented Aug 29, 2019

@dotnet-bot test

@singhsarab singhsarab changed the title [Draft] Html logger Html logger Aug 29, 2019
@singhsarab singhsarab merged commit 7317f22 into microsoft:master Aug 29, 2019
@RehanSaeed
Copy link

How do we make use of the new HTML logger? The docs need updating:

https://github.com/Microsoft/vstest-docs/blob/master/docs/report.md#syntax-of-default-loggers

@singhsarab
Copy link
Contributor

@RehanSaeed Thanks. the docs have been updated.

@RehanSaeed
Copy link

Is there a way to use it with dotnet test too? Executing this doesn't seem to work after upgrading my xUnit project to include 16.3.0 of the test SDK.

dotnet test --logger 'html;LogFileName=foo.html'

@singhsarab
Copy link
Contributor

@RehanSaeed This will be part of the dotnet sdk, and the 3.1.xx release will have it, it is still not out yet.

@RehanSaeed
Copy link

Cool! Is the syntax to support multiple loggers like this?

dotnet test --logger trx;LogFileName=foo.trx --logger html;LogFileName=foo.html

@dracos1993
Copy link

How to use this html logger with runsettings file? I tried via cli and it works, but no luck through the config file.

<LoggerRunSettings> <Loggers> <Logger friendlyName="html"> <Configuration> <LogFileName>test.html</LogFileName> </Configuration> </Logger> </Loggers> </LoggerRunSettings>

@ViktorHofer
Copy link
Member

@nohwnd can you please check if it's possible to enable the html logger via the .runsettings file? Thanks

@nohwnd
Copy link
Member

nohwnd commented May 4, 2020

@RehanSaeed yes that works, but you should put those options in quotes if you run them from bash / powershell because ; terminates the command and you would end up evaluating only half of the command. Or in powershell you can use the parsing terminator --%:

# cmd / bash / powershell
dotnet test --logger "trx;LogFileName=foo.trx" --logger "html;LogFileName=foo.html"

# or another way in powershell
dotnet test --% --logger trx;LogFileName=foo.trx --logger html;LogFileName=foo.html

@dracos1993

This is what you'd do from settings, I actually just copied it from the log and removed unneeded lines:

dotnet test --% --logger trx;LogFileName=foo.trx --logger html;LogFileName=foo.html --diag c:\temp\log.txt
<RunSettings>
  <RunConfiguration>
  </RunConfiguration>
  <LoggerRunSettings>
    <Loggers>
      <Logger friendlyName="trx" enabled="True">
        <Configuration>
          <LogFileName>foo.trx</LogFileName>
        </Configuration>
      </Logger>
      <Logger friendlyName="html" enabled="True">
        <Configuration>
          <LogFileName>foo.html</LogFileName>
        </Configuration>
      </Logger>
    </Loggers>
  </LoggerRunSettings>
</RunSettings>

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.

9 participants