testfx icon indicating copy to clipboard operation
testfx copied to clipboard

test without namespace causes null ref

Open SimonCropp opened this issue 4 years ago • 2 comments

The following class

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
    }
}

in this project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.4" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.4" />
    <PackageReference Include="coverlet.collector" Version="3.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

produces

PS C:\Code\TestProject1> dotnet test
  Determining projects to restore...
  Restored C:\Code\TestProject1\TestProject1\TestProject1.csproj (in 205 ms).
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  TestProject1 -> C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll
Test run for C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll (.NETFramework,Version=v4.8)
Microsoft (R) Test Execution Command Line Tool Version 17.0.0-preview-20210512-01
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[MSTest][Discovery][C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll] MSTestAdapter failed to discover tests in class 'UnitTest1' of assembly 'C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll' because Object reference not set to an instance of an object..
No test is available in C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

PS C:\Code\TestProject1>

Repro

Env

  • Windows 10
  • .NET SDK (6.0.100-preview.5.21302.13)

SimonCropp avatar Jun 25 '21 02:06 SimonCropp

@SimonCropp thanks for your feedback.

Haplois avatar Jun 25 '21 12:06 Haplois

@SimonCropp this needs to be fixed in our FQN code. We are assuming that there is always an namespace there.

nohwnd avatar Jun 29 '21 14:06 nohwnd

Hi @SimonCropp! Sorry it took us so much time to answer and fix your issue.

I have linked a PR that adds an integration test to show issue is fixed and ensures we don't regress.

We will include this change as part of release v3 of MSTest. We cannot ship it as a 2.2.11 release as we were forced to drop support of some .NET Framework to bump the version of Test Platform we are using.

Evangelink avatar Sep 27 '22 08:09 Evangelink

@Evangelink thanks so much. please reach out if you need someone to do some beta testing of version 3

SimonCropp avatar Sep 27 '22 08:09 SimonCropp

With pleasure! I will ping you when we release the preview version. Thanks!

Evangelink avatar Sep 27 '22 09:09 Evangelink

Hey @SimonCropp, we just released a pre-release version of MSTest v3.0.0. If you are still up to do some beta testing, we would really like to get your feedback as there are lots of cleanup/infra/bug fixes included already.

Evangelink avatar Nov 11 '22 11:11 Evangelink

@Evangelink yep it now works with test that have no namespace.

SimonCropp avatar Nov 11 '22 11:11 SimonCropp

Awesome thanks! If you are encountering any issue/regression with this pre-release, please raise an issue in the repo and we will make it high prio.

Evangelink avatar Nov 11 '22 13:11 Evangelink