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 Support for Templating in LogFileName #1876

Closed
RehanSaeed opened this issue Dec 23, 2018 · 7 comments
Closed

Add Support for Templating in LogFileName #1876

RehanSaeed opened this issue Dec 23, 2018 · 7 comments

Comments

@RehanSaeed
Copy link

RehanSaeed commented Dec 23, 2018

Description

The trx file produced from dotnet test is highly unique but terrible for humans:

[Username]_[MachineName]_2018-12-23_08_27_05.trx

I'd like to supply a LogFileName using some sort of template syntax:

trx;LogFileName=[ProjectName]-[Timestamp].trx

To output:

MyProject-2018-12-23_08_27_05.trx

There are various replacements that could take place in LogFileName:

  • TargetFramework e.g. net7.0
  • ProjectName
  • Timestamp
  • Username
  • MachineName

Why is this useful

We can now run dotnet test on a folder to run all tests. However, I want custom file names, so I end up not being able to use the new feature above.

foreach(var project in GetFiles("./Tests/**/*Test.csproj"))
{
    DotNetCoreTest(
        project.ToString(),
        new DotNetCoreTestSettings()
        {
            Configuration = configuration,
            Logger = $"trx;LogFileName={project.GetFilenameWithoutExtension()}.trx",
            NoBuild = true,
            NoRestore = true,
            ResultsDirectory = artifactsDirectory
        });
}

I'd like a template syntax, so I could write:


DotNetCoreTest(
    ".",
    new DotNetCoreTestSettings()
    {
        Configuration = configuration,
        Logger = $"trx;LogFileName=[ProjectName].trx",
        NoBuild = true,
        NoRestore = true,
        ResultsDirectory = artifactsDirectory
    });
@abhishkk
Copy link
Contributor

@RehanSaeed
We are adding timestamp in user provided logFileName (PR: #1877) because of Issue #1603
This will allow separate trx files for each test project.

Adding @cltshivash @PBoraMSFT @singhsarab for thoughts on adding template syntax for logFileName.

@ryanbrandenburg
Copy link

The problem with the solution that was used for #1603 is that when you pass in the LogFileName you have no way of knowing what name the resulting file will be. If instead it had been solved by giving us result.[targetFramework].trx we would know what to expect. Alternatively we could add TargetFramework to the list of replacements for this issue.

@abhishkk
Copy link
Contributor

abhishkk commented Mar 7, 2019

@ryanbrandenburg Currently loggers are not aware of target framework and thus are unable to write the target framework name in file naming.

Regarding LogFileName, it is always ensured that file name starts with the name given by the user.

@roelandvh
Copy link

The problem with the solution that was used for #1603 is that when you pass in the LogFileName you have no way of knowing what name the resulting file will be. If instead it had been solved by giving us result.[targetFramework].trx we would know what to expect. Alternatively we could add TargetFramework to the list of replacements for this issue.

We had a similar issue and fixed it by relying on shell wildcard expansion (i.e. "projectname.trx*").

@legrab
Copy link

legrab commented Mar 29, 2023

Any news on the possibility to include ProjectName in the naming of the output files?

@0xced
Copy link

0xced commented Mar 29, 2023

I recently learnt that you can control the loggers through MSBuild properties instead of dotnet test arguments. Thus it becomes easy to craft the log file name of your choice. Here's what I have added to the Directory.Build.props file in my tests directory:

<ItemGroup>
  <VSTestLogger Include="trx%3BLogFileName=TestResults-$(TargetFramework)-$(MSBuildProjectName).trx" />
  <VSTestLogger Include="html%3BLogFileName=TestResults-$(TargetFramework)-$(MSBuildProjectName).html" />
</ItemGroup>

<PropertyGroup Condition="$(ContinuousIntegrationBuild) == 'true'">
  <VSTestResultsDirectory>$(MSBuildThisFileDirectory)\..</VSTestResultsDirectory>
  <VSTestLogger>@(VSTestLogger)</VSTestLogger>
</PropertyGroup>

0xced added a commit to 0xced/testcontainers-dotnet that referenced this issue Jan 24, 2024
So that test results are available at a glance in the GitHub action run page.

Also give a proper name to the trx files in order to understand the test results, see microsoft/vstest#1876 (comment)
0xced added a commit to 0xced/testcontainers-dotnet that referenced this issue Jan 24, 2024
So that test results are available at a glance in the GitHub action run page.

Also give a proper name to the trx files in order to understand the test results, see microsoft/vstest#1876 (comment)
@nohwnd
Copy link
Member

nohwnd commented Jul 9, 2024

This is a new feature and won't be implemented, we are focusing on adding new features to Testing.Platform instead. https://aka.ms/testingplatform

@nohwnd nohwnd closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants