GGTS can't run grails unit tests: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal - unit-testing

I've recently upgraded from Java 6 to Java 7, and changed the Grails version accordingly to 2.3.8. Everything compiles and runs fine from the command line.
But I'm finding my version of GGTS (3.5.1.RELEASE) won't run unit tests from within the editor. I get the error:
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
I've tried completely importing the project from scratch - no joy.
The problem applies only to Grails-specific tests in GGTS, not when I run them from the command line. It happens during the Grails initialisation registerBeans() call. Which is pulled in by the #TestFor annotation (no annotation, no problem).
Looking at other error reports with the same error, I see this seems to be something to do with versions of xml-apis. I've tried putting
compile('xml-apis:xml-apis:2.0.2')
in the grails.project.dependency.resolution ... dependencies section of BuildConfig.groovy, but it has no effect.
Any suggestions what I might do instead?
Charles

My Grails guru suggested simply moving to IntelliJ - a good, if slightly costly, approach.
But to my frustration I found a different, but similar, error in that environment too. I realised that IntelliJ imports the Eclipse editor settings for the project.
So the solution turned out to be to delete all the editor-specific files for the project, and regenerate it from the Groovy/Grails sources alone.
Charles

Related

Resharper - Inconclusive: test not run on debugging

I have an issue very similar to this one.
Debugging any test in Resharper returns "Inconclusive: test not run". This occurs for every test, every solution, every project at my machine. Reinstalling VS2019 and Resharper didn't help. Running tests works fine.
I've debugged test using devenv.exe /ReSharper.LogFile C:\temp\resharper.log /ReSharper.LogLevel Verbose command and the result is this (a fragment of ~6900 lines file).
The first error says: “Method 'StartSessionAsync' in type 'ReSharperAwareWrapper' from assembly 'JetBrains.ReSharper.UnitTesting.MSTest.Provider, Version=777.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325' does not have an implementation.”
I tried all the popular answers in the post I've linked and nothing seems to help.
Code is .NET Core 3.1 based C# solution.
Resharper: 2020.1.4 | Visual Studio: 16.7.0
I've solved an issue by installing 2020 EAP version of resharper (2020.2 EAP). Seems like it's a bug in 2020.1.4 version.
I started to have exactly the same issue after i updated VS to 16.7. Funny thing is that it broke unit test debugging in Rider as well.
Microsoft has pushed new Microsoft.NET.Test.Sdk package, but looks like it does not help. As a workaround, you can launch test from VS Unit Test window, instead of Resharper's one.
For me it was because the test was unchecked at build time. So I had to checked the Unit Test projects in
Build -> Configuration Manager . check column build.
As #Peace says, you can update ReSharper, but if that does not help you can:
Reboot
Update Visual Studio: Help > Check for Updates
In addition to the answer given by #Mihails Popovs. Possible cause is that you do not have referenced the Microsoft.NET.Test.Sdk.

Guidance for running tests using MSTest v1 in Visual Studio 2017 15.8.1

I upgraded to Visual Studio 2017 last week. A solution with several test projects using MSTest v1 seemed to be fine at first. Most test projects execute tests fine. This is .NET Framework, not .NET Core.
However, there is one project where I am encountering issues. It's an integration test project, meaning it runs web application tests using the ChromeDriver and Selenium. This project references NUnit, though that reference comes from another project reference. I am not actually using NUnit as my test framework.
This is the error when trying to run any test in that particular test project:
Could not find test executor with URI 'executor://mstestadapter/v1'. Make sure that the test executor is installed and supports .net runtime version .
Test project {name} does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.
Disabling the option indicated below made everything work:
I found this solution after browsing the preview release notes at https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-preview-relnotes#--visual-studio-2017-version-158-preview-4 (scroll down to "... What's New ..." and then .NET Test Adapter Extension). It mentions this breaking change (though it didn't break my other projects), but there is no mention of what to actually do to solve the problem.
Of course, long-term, keeping that option unchecked doesn't seem feasible. So I am looking for guidance on how to proceed.
I already tried to see if I could "quickly" upgrade to MSTest v2, but that had an issue because System.Runtime 4.1.2 couldn't be found. I tried adding System.Runtime 4.3.0 via NuGet, but that didn't solve the issue.
I was getting a similar issue running Xamarin.UITests and resolved it by installing the "NUnit 2 Test Adapter" Extension in Visual Studio. In Visual Studio 2017 you do this from Tools > > Extensions and Updates... > Online > Search "NUnit Adapter" > click the NUnit 2 Test Adapter then the Download button to install. Restart Visual Studio when prompted to complete the installation.
It would be interesting to understand how the MSTest V1 framework assembly(Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll) is referenced in this project. The compatibility checkbox that also ended up being disabled in the image above should ensure that this project has MSTestV1 tests and enabled run tests. If it isn't then for some reason the detection logic is busted and needs to be fixed - a snippet on how the assembly is referenced would be helpful there.
As for moving to MSTest V2, this blog should help: https://blogs.msdn.microsoft.com/devops/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/ . And for the specific issue you seem to be running into, this github issue on the repo sounds similar: https://github.com/Microsoft/testfx/issues/184 .
Caltor's answer pretty much solved it for me: it was the NUnit Adapter I needed. But I followed slightly different steps. Here they are for VS 2019 (but probably apply to VS 17 too):
Right clicked on the References node under my project in the solution explorer
Chose "Manager NuGet packages"
Clicked Browse
Searched for nunit3testadapter
Hit install on the result that popped up
The issue for me was similar to the OP's - the adapter was installed on some projects but not others. But confusingly this wasn't immediately visible under the "References" node for that project. The only node relating to nunit under that References node said "nunit.framework". So the references for test with and without the adapter looked the same.
"... but that had an issue because System.Runtime 4.1.2 couldn't be found."
I think this is a setting in the app.config that does not get updated when the project settings are updated. I searched for System.Runtime under the packages folder and then changed my app.config to match what I found, and then that particular problem went away.

NUnit3 throws exception System.Runtime, Version=4.2.0.0 not found while trying to run test in NUnit3 console

Environment:
.Net Core 2.0
visual Studio Professional 2017
NUnit3
OpenCover (For code coverage)
ReportGenerator(For code coverage report)
Hi Nunit Team,
I am pretty familiar with MS Test framework and have worked on that extensively but was testing how suitable NUnit framework would be and so wanted to do a small POC around that. I created a small classlibrary and a unit test project. Below are the NuGet package been installed:
NUnit 3.7.1
But when I try to run the test cases from console runner like below I get exception saying System.Runtime, Version=4.2.0.0 assembly not found.
C:\Users\UN\.nuget\packages\nunit.consolerunner\3.8.0\tools>nunit3-console.exe D:\Code_Trials\BoMLibrary\BomTest\bin\Debug\netcoreapp2.0\BomTest.dll
Exception detail:
Errors, Failures and Warnings
Invalid : D:\Code_Trials\BoMLibrary\BomTest\bin\Debug\netcoreapp2.0\BomTest.dll
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
----> Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Run Settings
DisposeRunners: True
WorkDirectory: C:\Users\Smukherjee.nuget\packages\nunit.consolerunner\3.8.0\tools
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETCoreApp,Version=v2.0
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Am really not sure why so? No matter what I try not able to pass through this error. Moreover, when I try to install the assembly from Nuget I don't even find a assembly with version 4.2.0.0.
Tried installing the version 4.3.0.0 of System.Runtime but no luck. Can you please help on this.
Strange thing, I have got a sample unit test project (as part of opencover nuget install) which targets .Net Framework 4.5 and have NUnit2.6.7 package installed and when I try to run that using NUnit3 console it works like charm.
Even, installing NUnit3 latest stable version 3.10.1.0 doesn't help either. Also, it's surely not an Opencover issue since opencover console just passes the test run request to NUnit console. So the issue has to be around NUnit.
Let me know if you need more information around this.
Found the answer to this here https://github.com/nunit/nunit/issues/2763
NUnit Console doesn't run .NET Core tests - you need to use dotnet test instead. Take a look at this page:
https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

NCover not finding unit tests

I am trying to install NCover in an existing C# .NET project for work. Unfortunately, after I download NCover and installed the Visual Studio extension, it wasn't finding any of the unit tests. The answers I've seen/heard seem to be in the vain of 'It wasn't working...time passed...it started working.'
I can run the tests with Visual Studio's Test Explorer, but I need to get NCover installed to see the code coverage. I had NCover installed previously, and other people on my team are getting it to work within the same project.
I am using Visual Studio 2013 with the newest version of NCover Desktop (v 5.1).
I am getting two errors in the console log.
The first switches between saying:
Agent Error (v4x64): An error occurred while loading assembly
and
Agent Error (v4x64): There was a problem loading test assembly [test path]. Could not get bytes from loader AppDomain
The second (after I try to run NCover) says it 'Could not load config' for the test dll.
I copied the 4 XML config file (Bolt.ext.config, Bolt.Extension2008.dll.config, NCover.exe.config, ncover.axplorer.exe.config) from one of my team members, so I'm pretty sure that I have my config correct.
Has anyone else experience this/have any suggestions? Help would be greatly appreciated!
Further information:
When I hover over the grayed out test dll in the bolt test panel, I get the following error:
Assembly is not loaded. Select and run to build and load this assembly
I was looking at this post, but it doesn't seem like any of the solutions are working for me...
After working with some of the other developers in my office, we discovered the issue was with the NCover version. For our tests to run, we needed to use NCover v5.0. Neither v5.1 or v5.2 would work with our setup. Not sure what changed in v5.1 that wouldn't let it find the tests, but I'm glad it's working now :)

Visual Studio 2015 can't run unit test

Since I installed VS2015, I can't run unit tests on neither VS2013 nor VS2015
Below is the error:
Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.
Anybody experiencing the same problem?
I had the same problem (also after installing VS2015). What solved it for me was to move the solution. Others reported that "creating a new solution and adding all the projects again solved it". I think the test runner somehow marked the solution (via the path). So just changing the path works.
I think (but I did not try) that after a single successful run (move solution, open solution from new directory, running tests, closing solution, move back) everything could work again as the database should be setup correctly.