vstest
vstest copied to clipboard
Add Support for Templating in LogFileName
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
:
- 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
});
@RehanSaeed We are adding timestamp in user provided logFileName (PR: https://github.com/Microsoft/vstest/pull/1877) because of Issue https://github.com/Microsoft/vstest/issues/1603 This will allow separate trx files for each test project.
Adding @cltshivash @PBoraMSFT @singhsarab for thoughts on adding template syntax for logFileName.
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.
@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.
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*").
Any news on the possibility to include ProjectName in the naming of the output files?
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>