question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to run test because null with nested test classes.

See original GitHub issue

Environment 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

capture

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DustinCampbellcommented, Jan 27, 2017

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. 😄

1reaction
gregg-miskellycommented, Jan 26, 2017

Okay, I will reopen for now then.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found