Failed to run test because null with nested test classes.
See original GitHub issueEnvironment data
dotnet --info
output: 1.0.0-preview2-003133
VS Code version: 1.9.0-insider
C# Extension version: 1.6.2
Steps to reproduce
For us the problem was nested classes. OmniSharp cannot handle this, when we click run test
.
public class SomeClass
{
public class SomeMethod
{
// Trying to run this test causes
// "Failed to run test because null"
[Fact]
public void SomeTest()
{
}
}
}
Expected behavior
The test runs and the output says “Test Passed”.
Actual behavior
Failed to run test because null
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
JUnit test in nested Kotlin class not found when running gradle ...
Only non-static nested classes (i.e. inner classes) can serve as @Nested test classes. Marking the class as inner in Kotlin compiles to a ......
Read more >Mock-annotated fields are null for inner test classes (e.g. when ...
This issue would have happened with any Runner that enabled hierarchical test classes (such as the NitorCreations NestedRunner). JUnitRule ...
Read more >JUnit 5 Nested Class: @Nested Tutorial With Examples
An alternative and a better approach to this would be to create a nested class inside the main class and grouping together the...
Read more >Nested tests with Junit5 - Kotlin Testing
Nested tests in Junit5 allows us grouping test cases. Check how to do this in presenter ... We will use @Nested annotation and...
Read more >JUnit5 Tutorial - DigitalOcean
JUnit Nested Test Classes. Nested tests allow to create nested classes and execute all of its test methods. The inner classes must be...
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
OK. I see why the problem is specific to tests in nested classes. The offending line of code is here: https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.DotNetTest/Helpers/TestFeaturesDiscover.cs#L41.
Essentially, the code expects Roslyn’s
ISymbol.ToDisplayName()
to return a name that can be used with ‘dotnet test’. However, that method returns strings for display. Between a class and a nested class, it uses a ‘.’ separator. However, ‘dotnet test’ expects a metadata name when the class and nested class are separated by a ‘+’. I had to write code that produced a metadata name once before – for Code Model in VS (https://github.com/dotnet/roslyn/blob/master/src/VisualStudio/Core/Impl/CodeModel/MetadataNameHelpers.cs). Looks like I might have to do that again. 😄Okay, I will reopen for now then.