简体   繁体   English

将playframework测试作为IntelliJ IDEA JUnit运行配置运行

[英]Running playframework tests as a IntelliJ IDEA JUnit run configuration

I've been trying to run the unit tests in a play application from IntelliJ directly from the built in test runner. 我一直试图直接从内置的测试运行器在IntelliJ的播放应用程序中运行单元测试。 (To get the nice UI, click through etc.) (要获得漂亮的用户界面,请点击进入等)

This works for very basic FunctionalTest tests and when it starts it gives the following logging: 这适用于非常基本的FunctionalTest测试,当它启动时,它提供以下日志记录:

16:18:08,353 INFO  ~ Starting /home/sindrit/projects/testapp/.
16:18:08,370 INFO  ~ Module crud is available (/home/sindrit/play-1.2.3/modules/crud)
16:18:08,949 WARN  ~ You're running Play! in DEV mode
16:18:10,242 INFO  ~ Connected to jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
16:18:11,033 INFO  ~ Application 'testapp' is now started !

Indicating play is actually starting. 指示游戏实际上正在开始。

However more complicated tests using database access fail with exceptions like this: 但是,使用数据库访问的更复杂测试失败,例外情况如下:

java.lang.UnsupportedOperationException: Please annotate your JPA model with @javax.persistence.Entity annotation.
at play.db.jpa.GenericModel.count(GenericModel.java:232)
at model.BeanTest.testCreate(BeanTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
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 play.test.PlayJUnitRunner$StartPlay$1$1$1.execute(PlayJUnitRunner.java:73)
at play.Invoker$Invocation.run(Invoker.java:265)
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.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
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 org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)

I expect this is because the instrumentation is not working as it does when running play. 我希望这是因为仪器不能像运行游戏那样工作。 The same test runs fine in play auto-test . 相同的测试在play auto-test测试中运行良好。

Through some google searches I've found that I should need at lest the following parameters: 通过一些谷歌搜索,我发现我应该至少需要以下参数:

  • -javaagent:/home/sindrit/play-1.2.3/framework/play-1.2.3.jar -javaagent:/home/sindrit/play-1.2.3/framework/play-1.2.3.jar
  • -Dfile.encoding=utf-8 -Dfile.encoding = UTF-8
  • -Dplay.debug=yes -Dplay.debug = YES
  • -Dplay.id=test -Dplay.id =测试
  • -Dapplication.path=/home/sindrit/projects/testapp -Dapplication.path = /家庭/ sindrit /项目/ testapp

Has anyone here gotten this to work? 有没有人在这里工作?

What JVM parameters or classpath or other things do I need to make the IntelliJ test runner emulate the play runtime environment? 我需要哪些JVM参数或类路径或其他东西才能使IntelliJ测试运行器模拟播放运行时环境?

If I add play-testrunner.jar to the dependencies I get the following error: 如果我将play-testrunner.jar添加到依赖项中,我会收到以下错误:

play.exceptions.CompilationException: The type BasicTest is already defined
at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:412)
at play.Play.start(Play.java:485)
at play.test.PlayJUnitRunner.<init>(PlayJUnitRunner.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84)
at org.junit.runners.Suite.<init>(Suite.java:79)
at com.intellij.junit4.IdeaSuite.<init>(IdeaSuite.java:37)
at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:34)
at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:81)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:61)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)

I maybe over simplifying this but it seems you may have forgotten the Entity annotation on your database models. 我可能过度简化了这一点,但似乎你可能已经忘记了数据库模型上的Entity注释。

Your models should look like this. 你的模型应该是这样的。

@Entity
@Table( name = "pkg_load" )
public class PkgLoad extends Model {

}

Or this if you don't want to use the built in ID in model. 或者,如果您不想在模型中使用内置ID。

    @Entity
@Table( name = "pkg_load" )
public class PkgLoad extends GenericModel {

    @Id
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    @Basic( optional = false )
    @Column( name = "pkg_load_id" )
    public Long pkgLoadId;
}

http://www.playframework.org/documentation/1.2.3/jpa http://www.playframework.org/documentation/1.2.3/jpa

The Entity annotation is found in the javax.persistence library. 实体注释可在javax.persistence库中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM