-
Notifications
You must be signed in to change notification settings - Fork 390
Use Xunit.v3 (latest release) #1720
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
Changes from all commits
f8d57ba
013feab
78807f7
fcdd26d
e567eea
0447967
bdbe03d
4f6a6d3
59c1678
5666085
adf41b1
eca5e8c
1e09a04
d7d571d
b82996e
cf354b1
8eb7855
8ebd2cb
cea59f5
8d9e0db
64635c0
40148c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# build.sh - Helper script to build, package, and test the Coverlet project. | ||
# | ||
# This script performs the following tasks: | ||
# 1. Builds the project in debug configuration and generates a binary log. | ||
# 2. Packages the project in both debug and release configurations. | ||
# 3. Shuts down any running .NET build servers. | ||
# 4. Runs unit tests for various Coverlet components with code coverage enabled, | ||
# generating binary logs and diagnostic outputs. | ||
# 5. Outputs test results in xUnit TRX format and stores them in the specified directories. | ||
# | ||
# Usage: | ||
# ./build.sh | ||
# | ||
# Note: Ensure that the .NET SDK is installed and available in the system PATH. | ||
|
||
# Build the project | ||
dotnet build -c debug -bl:build.binlog | ||
dotnet pack -c debug | ||
dotnet pack -c release | ||
dotnet build-server shutdown | ||
|
||
# Run tests with code coverage | ||
dotnet test test/coverlet.core.tests/coverlet.core.tests.csproj -c debug --no-build -bl:test.core.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" -- --results-directory "artifacts/Reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.core.tests.trx" --diagnostic --diagnostic-output-directory "artifacts/log/debug" --diagnostic-output-fileprefix "coverlet.core.tests" | ||
dotnet build-server shutdown | ||
dotnet test test/coverlet.core.coverage.tests/coverlet.core.coverage.tests.csproj -c debug --no-build -bl:test.core.coverage.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" -- --results-directory "artifacts/Reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.core.coverage.tests.trx" --diagnostic --diagnostic-output-directory "artifacts/log/debug" --diagnostic-output-fileprefix "coverlet.core.coverage.tests" | ||
dotnet build-server shutdown | ||
dotnet test test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj -c debug --no-build -bl:test.msbuild.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" -- --results-directory:"artifacts/Reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.msbuild.tasks.tests.trx" --diagnostic --diagnostic-output-directory "artifacts/log/debug" --diagnostic-output-fileprefix "coverlet.msbuild.tasks.tests" | ||
dotnet build-server shutdown | ||
dotnet test test/coverlet.collector.tests/coverlet.collector.tests.csproj -c debug --no-build -bl:test.collector.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"artifacts/log/debug/coverlet.collector.test.diag.log;tracelevel=verbose" | ||
dotnet build-server shutdown | ||
dotnet test test/coverlet.integration.tests/coverlet.integration.tests.csproj -c debug --no-build -bl:test.integration.binlog -- --results-directory "artifacts/Reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.integration.tests.trx" --diagnostic --diagnostic-output-directory "artifacts/log/debug" --diagnostic-output-fileprefix "coverlet.integration.tests" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.112" | ||
"version": "8.0.113" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// Copyright (c) Toni Solarin-Sodara | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: System.Reflection.AssemblyKeyFileAttribute("coverlet.console.snk")] | ||
[assembly: InternalsVisibleTo("coverlet.integration.tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001d24efbe9cbc2dc49b7a3d2ae34ca37cfb69b4f450acd768a22ce5cd021c8a38ae7dc68b2809a1ac606ad531b578f192a5690b2986990cbda4dd84ec65a3a4c1c36f6d7bb18f08592b93091535eaee2f0c8e48763ed7f190db2008e1f9e0facd5c0df5aaab74febd3430e09a428a72e5e6b88357f92d78e47512d46ebdc3cbb")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using Coverlet.Core.Abstractions; | ||
|
||
|
@@ -54,7 +55,12 @@ public T Do<T>( | |
} | ||
return action(); | ||
} | ||
catch (Exception ex) | ||
catch (DirectoryNotFoundException) | ||
{ | ||
// do nothing | ||
return default; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I don't have that much time to look into everything but in which scenario we don't want to throw the exception? E.g. if someone/something deletes the temp directory with the orginal modules before we could restore them? Is this something we can just ignore because the user will be notified in another place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will suppress a retry for a not existing folder or not accessible folder. I had this situation which finally makes any retry useless. By the way, this code was copied a long time ago (2017) from stackoverflow. Newer comments states that this implementation is buggy and Polly was recommended as an alternative. |
||
} | ||
catch (IOException ex) | ||
{ | ||
exceptions.Add(ex); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,10 @@ | |
<ThresholdStat Condition="$(ThresholdStat) == ''">minimum</ThresholdStat> | ||
<ExcludeAssembliesWithoutSources Condition="$(ExcludeAssembliesWithoutSources) == ''"></ExcludeAssembliesWithoutSources> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' "> | ||
<CoverletToolsPath Condition=" '$(CoverletToolsPath)' == '' ">$(MSBuildThisFileDirectory)..\tasks\netstandard2.0\</CoverletToolsPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' "> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I don't understand this and it looks like something that could potentially lead to an issue where I'm searching for hours and hours to find it 😃 . Why we need this condition here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a small usability update. I use windows OS and was tired to update the string manually after the message with the path was written to the console. |
||
<CoverletToolsPath Condition=" '$(CoverletToolsPath)' == '' ">$(MSBuildThisFileDirectory)../tasks/netstandard2.0/</CoverletToolsPath> | ||
</PropertyGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Toni Solarin-Sodara | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Reflection; | ||
using Coverlet.Collector.DataCollection; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Coverlet.Collector.Tests.DataCollection | ||
{ | ||
public class CoverletInProcDataCollectorTests | ||
{ | ||
private readonly CoverletInProcDataCollector _dataCollector; | ||
|
||
public CoverletInProcDataCollectorTests() | ||
{ | ||
_dataCollector = new CoverletInProcDataCollector(); | ||
} | ||
|
||
[Fact] | ||
public void GetInstrumentationClass_ShouldReturnNullForNonMatchingType_EnabledLogging() | ||
{ | ||
// Arrange | ||
var dataCollectionSink = new Mock<IDataCollectionSink>(); | ||
var mockAssembly = new Mock<Assembly>(); | ||
var mockType = new Mock<Type>(); | ||
mockType.Setup(t => t.Namespace).Returns("Coverlet.Core.Instrumentation.Tracker"); | ||
mockType.Setup(t => t.Name).Returns("MockAssembly_Tracker"); | ||
mockAssembly.Setup(a => a.GetTypes()).Returns(new[] { mockType.Object }); | ||
Environment.SetEnvironmentVariable("COVERLET_DATACOLLECTOR_INPROC_EXCEPTIONLOG_ENABLED", "1"); | ||
_dataCollector.Initialize(dataCollectionSink.Object); | ||
|
||
// Act & Assert | ||
var results = _dataCollector.GetInstrumentationClass(mockAssembly.Object); | ||
|
||
// Assert | ||
Assert.Null(results); | ||
} | ||
|
||
[Fact] | ||
public void GetInstrumentationClass_ShouldReturnNullForNonMatchingType() | ||
{ | ||
// Arrange | ||
var mockAssembly = new Mock<Assembly>(); | ||
var mockType = new Mock<Type>(); | ||
mockType.Setup(t => t.Namespace).Returns("NonMatchingNamespace"); | ||
mockType.Setup(t => t.Name).Returns("NonMatchingName"); | ||
mockAssembly.Setup(a => a.GetTypes()).Returns(new[] { mockType.Object }); | ||
|
||
// Act | ||
var result = _dataCollector.GetInstrumentationClass(mockAssembly.Object); | ||
|
||
// Assert | ||
Assert.Null(result); | ||
} | ||
} | ||
} |
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.
We are not supporting
4.6.1
anymore? And nothing <net core 6
? I think we still can instrument the e.g. .NET Core 2.0 projects. But coverlet needs a .NET6 runtime to execute.At least with the
.NET Tool
I think it should still be possible?And can you tell/remind me why we have these constraints on the
collector
andmsbuild
drivers again. I see that they are bothnetstandard2.0
. Is it because of the libraries they are using?Uh oh!
There was an error while loading. Please reload this page.
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.
.NET Framework 4.7.2 is the first version which supports netstandard2.0 and we use nuget packages which require .NET 6.0 runtime. By the way, coverlet.collector.csproj file currently has only netstandard2.0 and we can change this in another PR.
see also current vstest collector example