test without namespace causes null ref
See original GitHub issueThe 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)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
C# says my namespace causes a NullReferenceException
A namespace can never be null, it will never generate any runtime errors of any kind (in the way you are describing it)....
Read more >NullReferenceException Class (System)
This exception occurs if you assume that each element of the array must contain a non-null value, and the value of the array...
Read more >c# - Have the unit test "using" the project, or just have same ...
I've used unit tests project with the same namespace as the real project (by manually removing the Tests suffix on the test project...
Read more >How to Stop NullReferenceExceptions in .NET
This article gives you a toolset for stopping NullReferenceExceptions in .NET code. The article centers around Nullable Reference Types ...
Read more >Null Reference Exceptions
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable isn't referencing an ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Evangelink yep it now works with test that have no namespace.
@Evangelink thanks so much. please reach out if you need someone to do some beta testing of version 3