Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NNnit3 "no test found to run" when ctor throws or protected #754

Closed
sm-g opened this issue Apr 25, 2017 · 8 comments
Closed

NNnit3 "no test found to run" when ctor throws or protected #754

sm-g opened this issue Apr 25, 2017 · 8 comments
Labels

Comments

@sm-g
Copy link

sm-g commented Apr 25, 2017

Given classes

class User {
  public User(int id)
  {
    if (id < 1)
       throw new ArgumentOutOfRangeException();
  }
}

class MappedUser{
  protected MappedUser(int id, string name) { ... }
  public static MappedUser Create() { ... }
}

and tests with AutoData using them.

NUnit3 test adapter and ctrl+R, ctrl+T does not show such tests. So I can write many tests, then change something in ctor and everything will be "ok".

I expected them to be visible and failing when try to run.

@sshushliapin
Copy link
Contributor

JFI, NUnitTestAdapter might be quite unstable.

@zvirja
Copy link
Member

zvirja commented Sep 5, 2017

@sm-g I've just tested your case using the following code:

public class User
{
    public User(int id)
    {
        if (id < 1)
            throw new ArgumentOutOfRangeException();
    }
}

public class MappedUser
{
    protected MappedUser(int id, string name) {}
    public static MappedUser Create()
    {
        return null;
    }
}

public class Tests
{
    [Test, AutoData]
    public void UserTest(User user)
    {
        
    }

    [Test, AutoData]
    public void MappedUserTest(MappedUser user)
    {
        
    }
}

My setup:

  • VS 2017 Update 3
  • Target Framework - 4.6.1
  • NUnit version - 3.8.1
  • NUnit3TestAdapter versin - 3.8.0

I've opened the VS Test window and run all the tests. Result:
image

Notice, we know about the issue that VS runner cannot handle test cases with dynamic test name. See PR #709 for more detail.

Could you please verify:

  • whether the issue is still present
  • whether issue is specific to VS runner only (e.g. no issues in R#, console)
  • whether the issue is that your tests are not being discovered, or that tests cannot be run as described here.

@zvirja
Copy link
Member

zvirja commented Oct 16, 2017

@sm-g Any chance to review my answer? So we could decide what to do with this issue..

@sm-g
Copy link
Author

sm-g commented Oct 18, 2017

Using you code, I got FileNotFound exception ("nunit.framework, Version=3.0.5797.27539, Culture=neutral, PublicKeyToken=2638cd05610744eb") when run tests with testdriven.net, and nothing in TestExplorer.

my setups as yours, and AutoFixture.NUnit3 - 3.51.0

However, when I remove any conditions from User ctor, nothing changes. Just no way to use AutoData.

@zvirja
Copy link
Member

zvirja commented Oct 18, 2017

@sm-g Could you please attach the solution that causes the issue? Also specify the version of VS you use.

I don't have TestDriven and can test with VS runner only.

@sm-g
Copy link
Author

sm-g commented Oct 19, 2017

http://ge.tt/8AldRym2

VS 15.4

@zvirja
Copy link
Member

zvirja commented Oct 20, 2017

@sm-g Thanks for sharing the project.

That happens because AssemblyBinding redirection generation is disabled in your project. That is not something specific to AutoFixture product itself - rather to how the .NET works.

To fix the issue add the following statements to the csproj file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{BE1E2536-4D83-428B-9760-54A135A71164}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>AutoFixtureRepro</RootNamespace>
    <AssemblyName>AutoFixtureRepro</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    
    <!-- Enable binding redirection generation -->
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
  </PropertyGroup>
...

After that everything will work fine. If you change the User constructor to always trigger the exception (i.e. without condition: throw new ArgumentOutOfRangeException();), the failed test will be still displayed in the VS Test Explorer:

image

Let me know whether now the original issue is solved.

@sm-g
Copy link
Author

sm-g commented Oct 20, 2017

Yes, thanks for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants