-
Notifications
You must be signed in to change notification settings - Fork 289
Open
Labels
Description
I have attempted to adapt the sample, but when I run, it doesn't detect any tests.
If I remove Program.cs, it will run and detect the tests.
With Program.cs, I get the following:
I have made the changes outlined below to the TestingPlatformExplorer sample project.
It feels like this should just work?
TestingPlatformExplorer.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>TestingPlatformExplorer</RootNamespace>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<EnableNUnitRunner>true</EnableNUnitRunner>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
<!-- Update to the last version if needed -->
<PackageReference Include="Microsoft.Testing.Platform" Version="1.9.1" />
<!-- Needed to support the Trx capability -->
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport.Abstractions" Version="1.9.1" />
<!-- <!– Add the trx extension –>-->
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.9.1" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.0.4" />
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="1.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="TestingPlatformExplorer.testingplatformconfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectCapability Include="DiagnoseCapabilities" />
<ProjectCapability Include="TestingPlatformServer" />
<ProjectCapability Include="TestContainer" />
</ItemGroup>
</Project>Program.cs
using System.Reflection;
using Microsoft.Testing.Platform.Builder;
using TestingPlatformExplorer.TestingFramework;
var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
// Register the testing framework
testApplicationBuilder.AddTestingFramework(() => new[] { Assembly.GetExecutingAssembly() });
using var testApplication = await testApplicationBuilder.BuildAsync();
return await testApplication.RunAsync();UnitTests.cs
using NUnit.Framework;
using TestingPlatformExplorer.TestingFramework;
using Assert = NUnit.Framework.Assert;
namespace TestingPlatformExplorer.UnitTests;
[TestFixture]
public class SomeTests
{
[Test]
public static void TestMethod1() => Assert.AreEqual(1, 1);
[Test]
public static void TestMethod2() => Assert.AreEqual(1, 2);
[Test]
public static void TestMethod3(ITestOutputHelper testOutputHelper)
{
testOutputHelper.WriteLine("I'm running TestMethod3");
try
{
int a = 1;
int b = 0;
int c = a / b;
Assert.AreEqual(c, 2);
}
catch (Exception ex)
{
testOutputHelper.WriteErrorLine(ex.ToString());
throw;
}
}
[Ignore("Temporary disabled")]
[Test]
public static void TestMethod4() => Assert.AreEqual(1, 1);
}