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

Test Explorer Picks up Zero Tests in VS 2017 for NUnit 2 #178

Closed
DanJ210 opened this issue Dec 13, 2018 · 23 comments
Closed

Test Explorer Picks up Zero Tests in VS 2017 for NUnit 2 #178

DanJ210 opened this issue Dec 13, 2018 · 23 comments

Comments

@DanJ210
Copy link

DanJ210 commented Dec 13, 2018

Where can I find a sample for NUnit 2? I have to use it for something but have spent the entire day trying to get it to work with zero success.

I can get NUnit 3 to work and with this sample but NUnit 2 just finds zero tests. I've installed NUnit framework 2.6.1 - 2.7 with the NUnitTestAdapter 2.0 - 2.1.1 trying all possible combinations. Below is my [TextFixture] and my [TestCase] which is an NUnit 2.0 syntax as shown below. I've searched all day and have tried every suggestion but no matter what I've not been able to get tests picked up using NUnit 2.

[TestFixture]
    public class UnitTest1
    {
        [TestCase]
        public void ProgrammerTest()
        {
            var address = new Address("56 Main St", "Mesa", "AZ", "38574");
            var customer = new Customer("John", "Doe", address);
            var company = new Company("Google", address);

            Assert.IsNullOrEmpty(customer.Id);
            customer.Save();
            Assert.IsNotNullOrEmpty(customer.Id);

            Assert.IsNullOrEmpty(company.Id);
            company.Save();
            Assert.IsNotNullOrEmpty(company.Id);

            Customer savedCustomer = Customer.Find(customer.Id);
            Assert.IsNotNull(savedCustomer);
            Assert.AreSame(customer.Address, address);
            Assert.AreEqual(savedCustomer.Address, address);
            Assert.AreEqual(customer.Id, savedCustomer.Id);
            Assert.AreEqual(customer.FirstName, savedCustomer.FirstName);
            Assert.AreEqual(customer.LastName, savedCustomer.LastName);
            Assert.AreEqual(customer, savedCustomer);
            Assert.AreNotSame(customer, savedCustomer);

            Company savedCompany = Company.Find(company.Id);
            Assert.IsNotNull(savedCompany);
            Assert.AreSame(company.Address, address);
            Assert.AreEqual(savedCompany.Address, address);
            Assert.AreEqual(company.Id, savedCompany.Id);
            Assert.AreEqual(company.Name, savedCompany.Name);
            Assert.AreEqual(company, savedCompany);
            Assert.AreNotSame(company, savedCompany);

            customer.Delete();
            Assert.IsNullOrEmpty(customer.Id);
            Assert.IsNull(Customer.Find(customer.Id));

            company.Delete();
            Assert.IsNullOrEmpty(company.Id);
            Assert.IsNull(Company.Find(company.Id));
        }
    }
@CharliePoole
Copy link
Contributor

Try using [Test]. Use [TestCase(...)] for tests with parameters.

@DanJ210
Copy link
Author

DanJ210 commented Dec 14, 2018

The above [TestCase] has no parameters but I changed it to [Test] anyway, I'm sure I tried it before too. It did pick up the tests briefly but after running and being told again that no tests were found, the test went back to a grayed out state of not being picked up. So I'm back to the same position of no tests being found.

This test case is a programmer's test from a company and they say that you have to create what is needed to pass all of the tests. They make clear to NOT change anything in the test, it's not a trick, the test works. They say to use NUnit 2.x due to the deprecation of some Assert functions in 3.x. So I'm like dumbfounded trying to understand why they can't change to 3.x which does work.

@DanJ210
Copy link
Author

DanJ210 commented Dec 14, 2018

And actually, if I change [Test] back to [TestCase] then the tests will get picked up in the explorer until I run the tests and am told "No test matches the given testcase filter."

@CharliePoole
Copy link
Contributor

When you say "picked up" do you mean the tests are discovered? That is, they are listed by the explorer? Are they always discovered?

Then when you run the test, they are shown as not run?

It's important to think about discovery and execution separately, since they are really separate.

BTW using TestCase with no args is risky. It's one of those "accidental" features and may work in some versions of nunit and not others.

@rprouse
Copy link
Member

rprouse commented Dec 15, 2018

I just tried my NUnit Test Project that I use for testing reported issues. It has NUnit 2 and 3 tests in it and it was working in earlier versions of Visual Studio, but tests are no longer appearing for me either. I am going to move this issue to the NUnit Adapter repository and continue to investigate. Visual Studio has been making a lot of changes recently and has likely broken the adapter with a recent update. One change that they have made is to require adapters to be copied into the bin directory which this version of the adapter does not do.

I will test, but in the meantime, you could run your tests using the NUnit Console, or installing the VSIX version of the adapter might work.

@rprouse rprouse transferred this issue from nunit/nunit-csharp-samples Dec 15, 2018
@rprouse
Copy link
Member

rprouse commented Dec 15, 2018

I tested in Visual Studio 2019. Tests are discovered, I think by Visual Studio, not by the adapter, but tests are not run. In the output window, it looks like only the 3.11 version of the adapter is being called.

@rprouse
Copy link
Member

rprouse commented Dec 15, 2018

I managed to get it to work. To do so, I had to go to Tools | Options | Test | General and uncheck the Active Solution performance checkbox. I then had to rebuild the solution. Once I did that, tests appeared and the NUnit 2.1.1.0 adapter started being listed in the output window. I believe the VSIX would also work.

image

If we want to fix this issue, I think we will need to move the adapter into the bin directory from the NuGet package like we did with the NUnit 3 adapter.

@DanJ210
Copy link
Author

DanJ210 commented Dec 17, 2018

Thanks @CharliePoole for the insight, I think they have been discovered by the test explorer because they would show up but not execute.

However, the solution that @rprouse suggested worked. I turned off the setting outlined above and I'm now stepping through the tests. So I'll use this solution for now. I was given specific instructions to change nothing in the test case given so I have to use what's there but I'm sure that's not what they use in their main day.

@vaindil
Copy link

vaindil commented Feb 20, 2019

I don't know if my issue is the same, but unchecking that box did not work for me. All of my tests are discovered by the Test Explorer, but when I try to run any of them I get "No test matches the given testcase filter...". I'm using the VSIX adapter. ReSharper is able to run the tests no problem, but I can't run them without it.

[2/20/2019 1:00:51 PM Informational] ------ Run test started ------
[2/20/2019 1:00:54 PM Informational] NUnit VS Adapter 2.1.1.0 executing tests is started
[2/20/2019 1:00:59 PM Informational] Loading tests from C:\fakepath\bin\Debug\UnitTests.fakename.dll
[2/20/2019 1:01:01 PM Warning] Dependent Assembly  of C:\fakepath\bin\Debug\UnitTests.fakename.dll not found. Can be ignored if not a NUnit project.
[2/20/2019 1:01:01 PM Informational] NUnit VS Adapter 2.1.1.0 executing tests is finished
[2/20/2019 1:01:01 PM Warning] No test matches the given testcase filter `FullyQualifiedName=UnitTests.fakename.DatabaseTests.TablesExist` in C:\fakepath\bin\Debug\UnitTests.fakename.dll
[2/20/2019 1:01:01 PM Informational] ========== Run test finished: 0 run (0:00:09.9752465) ==========

@OsirisTerje
Copy link
Member

@vaindil Ok, I'll try to take a look at it. If you by any chance have a small repro that compiles "as is", it would be awesome.

@workgroupengineering
Copy link

i have similar issue.

My configuration is

Visual studio 2017 9.11
NUnit VS Adapter 2.1.1.0
NUnit 2.7.0
Microsoft.NET.Test.Sdk 15.9.0
Test project target .NET 3.5
The adapter is deployed by nuget

When try discovery the test in output window show this messages:
[13/05/2019 11:11:48 Informational] NUnit VS Adapter 2.1.1.0 executing tests is started [13/05/2019 11:11:49 Informational] Loading tests from C:\GitHub\FatturaElettronica.NET\src\Test(3.5)\bin\Debug\net35\FatturaElettronica.Test.dll [13/05/2019 11:11:49 Error] Exception thrown executing tests in C:\GitHub\FatturaElettronica.NET\src\Test(3.5)\bin\Debug\net35\FatturaElettronica.Test.dll [13/05/2019 11:11:49 Error] System.InvalidOperationException: Operazione non valida a causa dello stato corrente dell'oggetto. in Mono.Cecil.ModuleDefinition.ProcessDebugHeader() in Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters) in Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters) in Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in NUnit.VisualStudio.TestAdapter.NavigationDataProvider.CacheTypes(String assemblyPath) in NUnit.VisualStudio.TestAdapter.NavigationDataProvider.GetNavigationData(String className, String methodName) in NUnit.VisualStudio.TestAdapter.TestConverter.MakeTestCaseFromNUnitTest(ITest nunitTest) in NUnit.VisualStudio.TestAdapter.TestConverter.ConvertTestCase(ITest test) in NUnit.VisualStudio.TestAdapter.AssemblyRunner.AddTestCases(ITest test) in NUnit.VisualStudio.TestAdapter.AssemblyRunner.AddTestCases(ITest test) in NUnit.VisualStudio.TestAdapter.AssemblyRunner.AddTestCases(ITest test) in NUnit.VisualStudio.TestAdapter.AssemblyRunner.AddTestCases(ITest test) in NUnit.VisualStudio.TestAdapter.AssemblyRunner.AddTestCases(ITest test) in NUnit.VisualStudio.TestAdapter.AssemblyRunner.TryLoadAssembly() in NUnit.VisualStudio.TestAdapter.AssemblyRunner.RunAssembly(IFrameworkHandle testLog)
I've tried all your suggestions, but I haven't solved them.

I tried to downgrade the adapter to 2.0.0.0.
The tests are discovered.

@OsirisTerje
Copy link
Member

@workgroupengineering Can you upload a small repro ?

@workgroupengineering
Copy link

@OsirisTerje Here is an example repository.

@OsirisTerje
Copy link
Member

@workgroupengineering Thanks for the repo. The issue is caused by using the new SDK style project format. If you create the project with the Traditional style project format (either packages.config or package reference, both should work), then it works. I tested it out with such a project and then it finds the adapter and runs correctly.
There is something in the way the new VS works with the new project format causing this issue. I've tried to manually check if I get it right, but not. The easiest work around right now is to use the Traditional Project format.
Btw : What is the reason for using NUnit2 and not NUnit3 ?

@workgroupengineering
Copy link

Thanks @OsirisTerje,
it is strange that it works with version 2.0.0 and not with 2.1.1.
I use NUnit 2.0 because NUnit3 is not compatible with .Net 3.5

@OsirisTerje
Copy link
Member

NUnit3 is compatible with .net 3.5. It is not compatible with 2.0, but 3.5 works. And, I just checked it again on the project, updated to 3.11 framework and 3.13 adapter, and it works.

Also, the test projects could well be running under a higher framework, even if the SUT is targeting 3.5.

@OsirisTerje
Copy link
Member

@workgroupengineering When you say it works with 2.0 and not 2.1, that is the framework, which should not affect this at all. Did you use the same adapter version in both cases ?

@rprouse
Copy link
Member

rprouse commented May 14, 2019

I use NUnit 2.0 because NUnit3 is not compatible with .Net 3.5

@workgroupengineering why do you say that NUnit 3 is not compatible with .NET 3.5? NUnit 3 has always had .NET 3.5 targets. In fact, until the upcoming 3.12 release, it still has .NET 2.0 targets.

@workgroupengineering
Copy link

Hi @rprouse
When I tried in multi target project, Visual Studio tells me that the target was invalid.
I will try again.

@rprouse
Copy link
Member

rprouse commented May 15, 2019

Thanks @workgroupengineering. It should work, our NUnit tests target everything from .NET 3.5 to .NET Core and run fine. If you can create a repro for us, we can look at it for you.

@OsirisTerje
Copy link
Member

@rprouse See my answer above, #178 (comment), and if you want to have another look, check his repro here https://github.com/workgroupengineering/Issue178

I have also forked his repro and added the Traditional style, see https://github.com/OsirisTerje/Issue178, branch FixNUnit. :-)

@workgroupengineering
Copy link

@rprouse after update VS at 15.9.2 the issue is resolved

@OsirisTerje
Copy link
Member

@workgroupengineering @DanJ210 Just released 2.2 of the adapter. It should work with these now. See details here: http://hermit.no/new-version-of-the-nunit-2-adapter-supporting-visual-studio-2019/

@OsirisTerje OsirisTerje added this to the 2.2 milestone Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants