Eclipse JUnit runner in play 1.2 doesn't work as expected

372 views
Skip to first unread message

Daniel Wagner

unread,
Apr 16, 2011, 8:05:31 PM4/16/11
to play-fr...@googlegroups.com
Hi,

I was hoping that someone might help me with at least one of the following 2 problems. I'm hoping that I might just be doing something stupid that is easy to fix! :)

I migrated a play 1.1 project that uses Morphia to play 1.2. One of the new features in play 1.2 is that it allows you to run the unit tests from inside Eclipse - I was quite excited and tried running the very few tests that I had previously created and they worked nicely. I then created a few more tests (everything worked) and then decided to split them up into two separate classes that extend UnitTest. At that point, the tests would fail with the following exception:

> java.lang.UnsupportedOperationException: Please annotate your model with @com.google.code.morphia.annotations.Entity annotation.
> at play.modules.morphia.Model.count(Model.java:399)
> at ModelTest.client(ModelTest.java:20)
> [...]

I thought this was strange and so moved the test back into the other class, where it works just fine. In fact, having the same code in two different test classes makes it work in BasicTest and fail in ModelTest (my new class). This is my first problem, which I can't seem to solve. It is worth mentioning that when using the play testrunner ("play test" and then running the tests in a browser) they all work! Therefore I would argue that this is not Morphia-related. However, if I just copy the existing BasicTest.java the copy runs just fine... does anyone have any ideas?

Now on to my second problem: I thought that maybe the new test file needed to be included in some configuration and so ran "play eclipsify". The result of this was that when I now right-click my project and select run as -> JUnit test, no tests are executed and I receive the following exceptions for all of the present test classes:

> Class not found BasicTest
> java.lang.ClassNotFoundException: BasicTest
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

This problem disappears when I select Project -> clean. Running eclipsify again will ruin my test setup again. This problem can also be observed with a new empty project. Steps to reproduce:
"play new myproj"
"play eclipsify myproy"
(import project into eclipse, junit works nicely)
"play eclipsify myproy"
(update eclipse, junit is broken)

Indeed, deleting the project and importing it again fixes the setup (and that is what the message says I should do) - but given that NOTHING has changed in the project between the two runs of "play eclipsify" it seems very difficult to believe that it would have anything to do with dirty caches... cleaning the project also works, but it still seems like odd behaviour. What am I doing wrong here? I'm running Eclipse Helios if that makes any difference.

If anyone could help me with my first problem that would be fantastic and of course if you have some idea what I'm doing wrong with my second problem that would be helpful too :)

Thanks,
Daniel

green

unread,
Apr 17, 2011, 12:24:23 AM4/17/11
to play-fr...@googlegroups.com
From the exception static, it's clear that the Model you are testing has not been enhanced by MorphiaEnhancer, which should be called upon application startup. But it looks weird that BasicTest works with the same code. What if you rename BasicTest to ModelTest?

BTW, how to run the test in Eclipse? Is there any special configuration need to set?

Regards,
Green

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Daniel Wagner

unread,
Apr 17, 2011, 3:42:07 PM4/17/11
to play-fr...@googlegroups.com
Hi!
Thanks for your quick reply. In the mean time I managed to narrow the problem down a bit further:
Whichever test is executed first will succeed, the SECOND one that uses Morphia will fail. If I then manually right-click on the failed test (the one that shows the UnsupportedOperationException) and select run - this will run only that test case - it works just fine.

Any suggestions on that one? I suspect something is wrong with the way the Eclipse JUnit runner executes the tests, as the Play JUnit runner still works.

I run my tests by right-clicking the entire project and selecting run as -> JUnit test. I never set any special configuration.

Thanks again for your help!
Daniel

Daniel Wagner

unread,
Apr 17, 2011, 6:39:39 PM4/17/11
to play-fr...@googlegroups.com
Actually, I toyed around a bit more with a new project and couldn't quite nail things down as to when happens. To help with things I created a minimal project that on my machine exhibits this problem of non-running tests. Funnily enough, I didn't even need to create another JUnit class - the "BasicTest" fails. Somehow I can't help but think that I'm doing something wrong?

Please find the minimal project attached. Eclipsifying it and running the project as a JUnit test case should result in the behaviour I mentioned before. Can anyone confirm this on their machine?

Thanks, Daniel

This is the error I'm seeing here with the attached project:
java.lang.UnsupportedOperationException: Please annotate your model with @com.google.code.morphia.annotations.Entity annotation.
at play.modules.morphia.Model.count(Model.java:399)
at BasicTest.myFirstTest(BasicTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at play.test.PlayJUnitRunner$StartPlay$1$1$1.execute(PlayJUnitRunner.java:73)
at play.Invoker$Invocation.run(Invoker.java:264)
at play.Invoker.invokeInThread(Invoker.java:67)
at play.test.PlayJUnitRunner$StartPlay$1$1.evaluate(PlayJUnitRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
brokenjunit.zip

Nicolas

unread,
Apr 18, 2011, 4:21:45 PM4/18/11
to play-fr...@googlegroups.com
I can't contribute to the solution other than that I can confirm, that the supplied minimal project fails on my setup as well.

Hank Zhu

unread,
Apr 27, 2011, 5:26:29 AM4/27/11
to play-fr...@googlegroups.com
Same issue here. All JPA models and thread (e.g. Params) related test cases are all failed.

I tried add -Dplay.id=test -Djava.endorsed.dirs="${play_home}/framework/endorsed" -javaagent:"${play_home}/framework/play.jar" to the JUnit launch configuration but no help.

Daniel Wagner

unread,
May 2, 2011, 7:07:12 PM5/2/11
to play-fr...@googlegroups.com
Any updates on this issue? :(

Daniel

Lauri Kimmel

unread,
May 4, 2011, 6:15:39 PM5/4/11
to play-framework
Reply all
Reply to author
Forward
0 new messages