I have a project with following structure:
multiplatformmodule - contains a single kotlin class SomeMultiPlatformClass
jvmmodule - a pure jvm module which depends on multiplatformmodule
The problem is that within the jvmmodule I can't access any class from multiplatformmodule when running a test. I get java.lang.NoClassDefFoundError: com/example/multiplatform/multiplatformmodule/SomeMultiPlatformClass. IDE (Anroid Studio) also marks this class as unresolved. It builds, however, when the multplatformmodule classes are accessed from another multiplatform module.
Much more can be seen in the example project https://github.com/micHar/kmm-dependency-issues/tree/master.
I cloned your repo and opened it with Intellij 2020.3.1 and it seems to resolve SomeMultiPlatformClass fine. I tried to run tests from the IDE, which didn't work for different reasons. When I changed the #Test to point to kotlin.test.Test the IDE also ran the tests fine.
https://github.com/kpgalligan/kmm-dependency-issues
This is clearly an Android Studio bug. Running your project with gradle, i.e. ./gradlew test will run the test (SomeJvmTest) just fine.
Related
I am using kotlin multiplatform project with js/jvm subprojects.
I used to have unit tests in jvm subproject (annotated using kotlin test annotations) and I easily ran tests using rightclick + Run 'xxx' test using junit. That option is not possible once I move those tests to common module instead.
I can still run tests using command line gradle and I even managed to create working Run configuration that worked, but I am missing that simple "right click to run" on class or even specific test method for convenience.
Is there any way to achieve that in project?
Thanks!
Which Kotlin version do you use? There was a bug with test gutters in 1.2.60, but it is fixed in the very next release which is expected to be at the beginning of the next week.
It actually should work as you described, so if it's not the version with the bug, then it's better to submit it.
I am trying to use NUnit for unit testing in my code base. When I try to run my test cases using ReSharper, I get:
"System.IO.FileNotFoundException: Could not load file or assembly
'ServicesTests.dll' or one of its dependencies.
ServicesTests is my class lib for my unit tests.
I have also tried to install the NUnit Test Adapter as described here but do not see my test cases in the Test Explorer.
Any ideas on what might be happening? Below are images of my class library from the solution explorer, the test explorer, ReSharper screen.
I was able to test using Nunit3 and VS2015 with Test Explorer after I changed the type of class library I was creating. Initially I was creating a Class Library (Package) and when I switched to Class Library it worked (see image below). I am still not able to use Resharper since I am using Nunit3 beta and that is currently unsupported by Resharper.
I have a similar issue also. The best answer I've come across to solve it is try and rebuild the solution (cleans and builds), or just resort to MS Test. It's a pain to convert the tests though...
Hope this helps.
EDIT:
My NUnit runs, but no tests "exist", despite having a project, classes, and methods all correct.
ReSharper does not support running unit tests in DNX projects https://youtrack.jetbrains.com/issue/RSRP-446679.
I know this is an old question but I had a similar issue recently in VS 2017. Use the Fusion Log Viewer (aka "Assembly Binding Log Viewer") to see what assembly is failing to load:
I created a test framework to test a sample application. This basically required creating a Solution for my sample application and then adding a Native Test Project, which can test the application.
The test project generates an .exe, but if I were to execute the .exe on it's own, it does nothing.
Is there a way to get information from the test programme so it can be used for other purposes outside of the VS environment?
Yes, you can run unit tests without VS2013.
Use Run automated tests from the command line using MSTest source to do so.
In general it says:
Open a Visual Studio command prompt.
Either change directory to your solution folder or, when you run the MSTest.exe program in step 3, specify a full or relative path to the metadata file or to the test container.
Run the MSTest.exe program.
I hope it will solve your issue.
It took a couple of days, but I've found that DeJaVo's answer is incorrect. Because I am running a Native Test Project, MSTest will not work with it. To run a Native Test from the command line, use VSTest.Console.
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
Another day, another problem with VS2012 and unit tests: Our solution has three test projects, together containing 335 different unit tests. All of these tests successfully run locally on different machines, but when checked in to our TFS 2012 build server, each time only 235 tests are being discovered.
There are 15 different test classes containing the unit tests, some of them using the new Fakes framework, others MOQ, some none or both. All of the classes reside in test projects (assemblies) ending in Test, the classes themselves are all ending in Test.
Some classes are not being discovered at all during the test run as part of the build process, in other classes e.g. 8 out of 12 tests are discovered and run.
Taking the "8 out of 12" example, the [ProjectNameTest].dll that's being generated shows all 12 tests using .NET Reflector 7.0, it's just so that some of the tests aren't run. I also cannot find any similarities (e.g. tests using Fakes / MOQ / ...) among the tests not run / discovered.
The build settings being used define the Test Sources Spec as **\*.dll (it used to be **\*test*.dll, but I changed this just to make sure that all files are taken into account).
For the Run Settings I initially started of with no Run Settings File and CodeCoverageEnabled. As part of trying to solve the problems I also changed this to a user defined UnitTest.runsettings file, unfortunately with the same result.
Does anybody know why there are all these problems? What might be the reasons? VS2010 and Moles worked a lot better, VS2012 has been causing a lot of trouble recently.
Update
Months later we finally updated the TFS installation to Update 3, but this made things even worse. Unit tests on the build server don't run anymore at all. Enabling dumps and analysing them showed that a StackOverflowException is thrown, but there is no indicator about the test that might be causing it. Again, locally on different developer systems the tests run without any problems.
We are considering opening a call at Microsoft as we've spent far too much time getting the whole thing to work (again). Moles were a whole lot better... I will keep this updated as soon as there is some kind of progress.
Update 2
Another few weeks have passed, and no real solution yet. As we have moved from VS2012 to VS2013 (Premium each time) now, we discovered that all tests are now run as part of the build process (again). Unfortunately, we still have problems getting all tests to pass - locally, everything runs fine on multiple systems, on the build server about ten percent of test fail. Investigation to be continued...
Usually, when tests pass locally but not on the build server, you probably need to include your assembly dependencies or if your tests are using databases you are connecting to the database properly.
Finally an answer was found - the problems with test failing randomly on the TFS build server were caused by using the Microsoft Fakes Framwork. On our local systems, everything worked as expected - we had Fakes defined in our different unit test projects (generally one test project for each "normal" project).
On the build server all the fakes were generated in the same directory, therefore depending on the build order of the projects (which in parts may be different for each build), the fakes generated first were overwritten by the fakes from the following project etc.
Instead of having the fake definitions as part of every project in our solution, we changed it so that we have a solution wide definition of fakes (e.g. System.Web.Fakes.dll) that we link to from each test project where we need it (Add existing item => Add as link). This solved the problems with running the unit tests on the build server, all tests pass again.