Skip to content

Commit

Permalink
Fix: BeforeTestRun not run in .NET462 up to .NET481 in multitarget te…
Browse files Browse the repository at this point in the history
…st project (#146) (#148)

* enable test runners for portability tests

* improve tests

* Fix: BeforeTestRun not run in .NET462 up to .NET481 in multitarget test project (#146)
  • Loading branch information
gasparnagy authored May 29, 2024
1 parent 2803707 commit 61c7505
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<ProjectConfiguration>
<Settings>
<XUnit2Enabled>False</XUnit2Enabled>
<CustomBuildProperties>
<Value>TargetFrameworks = netstandard2.0</Value>
</CustomBuildProperties>
</Settings>
</ProjectConfiguration>
5 changes: 4 additions & 1 deletion .ncrunch/Reqnroll.xUnit.ReqnrollPlugin.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<ProjectConfiguration>
<Settings>
<XUnit2Enabled>False</XUnit2Enabled>
</Settings>
<CustomBuildProperties>
<Value>TargetFrameworks = netstandard2.0</Value>
</CustomBuildProperties>
</Settings>
</ProjectConfiguration>
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# [vNext]

## Bug fixes:

* Fix: BeforeTestRun not run in .NET462 up to .NET481 in multitarget test project (#146)

# v2.0.0 - 2024-05-22

## Breaking changes:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<NuspecFile>$(MSBuildThisFileDirectory)Reqnroll.xUnit.nuspec</NuspecFile>
<AssemblyOriginatorKeyFile>$(Reqnroll_KeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
<dependency id="xunit.core" version="2.4.2" />
<dependency id="Xunit.SkippableFact" version="1.4.13" />
</group>
<group targetFramework=".NETFramework4.6.2">
<dependency id="Reqnroll" version="[$version$]" />
<dependency id="Reqnroll.Tools.MsBuild.Generation" version="[$version$]" />
<dependency id="xunit.core" version="2.4.2" />
<dependency id="Xunit.SkippableFact" version="1.4.13" />
</group>
</dependencies>
</metadata>

<files>
<file src="build\**\*" exclude="build\*.template.*" target="build" />
<file src="bin\$config$\netstandard2.0\Reqnroll.xUnit.ReqnrollPlugin.*" target="lib\netstandard2.0" />
<file src="bin\$config$\net462\Reqnroll.xUnit.ReqnrollPlugin.*" target="lib\net462" />

<file src="bin\$config$\netstandard2.0\Reqnroll.xUnit.Generator.ReqnrollPlugin.dll" target="build\netstandard2.0" />
<file src="bin\$config$\netstandard2.0\Reqnroll.xUnit.Generator.ReqnrollPlugin.pdb" target="build\netstandard2.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<AssemblyOriginatorKeyFile>$(Reqnroll_KeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>
Expand Down
42 changes: 29 additions & 13 deletions Tests/Reqnroll.SystemTests/Portability/PortabilityTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Reqnroll.TestProjectGenerator.Driver;
using System;
using System.Runtime.InteropServices;
using Reqnroll.TestProjectGenerator.Data;
using System.Collections.Generic;

namespace Reqnroll.SystemTests.Portability;

Expand All @@ -12,8 +14,24 @@ namespace Reqnroll.SystemTests.Portability;
[TestCategory("Portability")]
public abstract class PortabilityTestBase : SystemTestBase
{
public static IEnumerable<object[]> GetAllUnitTestProviders()
{
return [
[UnitTestProvider.MSTest],
[UnitTestProvider.NUnit3],
[UnitTestProvider.xUnit],
];
}

private void RunSkippableTest(Action test)
{
//TODO: Temporarily disabled tests until https://github.com/reqnroll/Reqnroll/issues/132 is resolved
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
_testRunConfiguration.UnitTestProvider == UnitTestProvider.xUnit &&
(_testRunConfiguration.TargetFramework == TargetFramework.Net462 ||
_testRunConfiguration.TargetFramework == TargetFramework.Net472))
Assert.Inconclusive("Temporarily disabled tests until https://github.com/reqnroll/Reqnroll/issues/132 is resolved");

try
{
test();
Expand All @@ -26,20 +44,12 @@ private void RunSkippableTest(Action test)
}

[TestMethod]
[DataRow(UnitTestProvider.MSTest)]
[DataRow(UnitTestProvider.NUnit3)]
[DataRow(UnitTestProvider.xUnit)]
[DynamicData(nameof(GetAllUnitTestProviders), DynamicDataSourceType.Method)]
public void GeneratorAllIn_sample_can_be_handled(UnitTestProvider unitTestProvider)
{
_testRunConfiguration.UnitTestProvider = unitTestProvider;
RunSkippableTest(() =>
{
//TODO: Temporarily disabled tests until https://github.com/reqnroll/Reqnroll/issues/132 is resolved
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
unitTestProvider == UnitTestProvider.xUnit)
Assert.Inconclusive("Temporarily disabled tests until https://github.com/reqnroll/Reqnroll/issues/132 is resolved");

_testRunConfiguration.UnitTestProvider = unitTestProvider;

PrepareGeneratorAllInSamples();

ExecuteTests();
Expand All @@ -50,8 +60,10 @@ public void GeneratorAllIn_sample_can_be_handled(UnitTestProvider unitTestProvid

[TestMethod]
[TestCategory("MsBuild")]
public void GeneratorAllIn_sample_can_be_compiled_with_MsBuild()
[DynamicData(nameof(GetAllUnitTestProviders), DynamicDataSourceType.Method)]
public void GeneratorAllIn_sample_can_be_compiled_with_MsBuild(UnitTestProvider unitTestProvider)
{
_testRunConfiguration.UnitTestProvider = unitTestProvider;
RunSkippableTest(() =>
{
PrepareGeneratorAllInSamples();
Expand All @@ -62,8 +74,10 @@ public void GeneratorAllIn_sample_can_be_compiled_with_MsBuild()

[TestMethod]
[TestCategory("DotnetMSBuild")]
public void GeneratorAllIn_sample_can_be_compiled_with_DotnetMSBuild()
[DynamicData(nameof(GetAllUnitTestProviders), DynamicDataSourceType.Method)]
public void GeneratorAllIn_sample_can_be_compiled_with_DotnetMSBuild(UnitTestProvider unitTestProvider)
{
_testRunConfiguration.UnitTestProvider = unitTestProvider;
RunSkippableTest(() =>
{
PrepareGeneratorAllInSamples();
Expand All @@ -75,8 +89,10 @@ public void GeneratorAllIn_sample_can_be_compiled_with_DotnetMSBuild()

#region Test before/after test run hooks (.NET Framework version of Reqnroll is subscribed to assembly unload)
[TestMethod]
public void TestRun_hooks_are_executed()
[DynamicData(nameof(GetAllUnitTestProviders), DynamicDataSourceType.Method)]
public void TestRun_hooks_are_executed(UnitTestProvider unitTestProvider)
{
_testRunConfiguration.UnitTestProvider = unitTestProvider;
RunSkippableTest(() =>
{
AddSimpleScenario();
Expand Down

0 comments on commit 61c7505

Please sign in to comment.