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

作为IntelliJ IDEA JUnit运行配置运行playframework测试,junit,intellij-idea,playframework,Junit,Intellij Idea,Playframework,我一直在尝试直接从内置测试运行程序在IntelliJ的play应用程序中运行单元测试。(要获得漂亮的用户界面,请点击浏览等) 这适用于非常基本的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/cru

我一直在尝试直接从内置测试运行程序在IntelliJ的play应用程序中运行单元测试。(要获得漂亮的用户界面,请点击浏览等)

这适用于非常基本的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 !
表明游戏实际上正在开始

但是,使用数据库访问的更复杂测试失败,出现以下异常:

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)
我认为这是因为仪器没有像运行play时那样工作。相同的测试在
播放自动测试中运行良好

通过一些谷歌搜索,我发现我至少需要以下参数:

  • -javaagent:/home/sindrit/play-1.2.3/framework/play-1.2.3.jar
  • -文件编码=utf-8
  • -Dplay.debug=是
  • -Dplay.id=测试
  • -Dapplication.path=/home/sindrit/projects/testapp
这里有人用过这个吗

要使IntelliJ测试运行程序模拟play运行时环境,我需要哪些JVM参数、类路径或其他东西

如果将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)
play.exceptions.CompilationException:已定义类型BasicTest
播放时.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
位于org.eclipse.jdt.internal.compiler.compiler.handleInternalException(compiler.java:672)
位于org.eclipse.jdt.internal.compiler.compiler.compile(compiler.java:516)
运行时.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
播放时.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:412)
play.play.start(play.java:485)
play.test.PlayJUnitRunner.(PlayJUnitRunner.java:31)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
位于java.lang.reflect.Constructor.newInstance(Constructor.java:513)
位于org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
位于org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
位于org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
位于org.junit.internal.builders.AllDefaultPossibilityBuilder.runnerForClass(AllDefaultPossibilityBuilder.java:29)
位于org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
位于org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93)
位于org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84)
位于org.junit.runners.Suite.(Suite.java:79)
在com.intellij.junit4.IdeaSuite上(IdeaSuite.java:37)
位于com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:34)
位于com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:81)
位于com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:61)
位于com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
位于com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
位于com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)

我可能过于简化了,但您可能忘记了数据库模型上的实体注释

你的模型应该是这样的

@Entity
@Table( name = "pkg_load" )
public class PkgLoad extends 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;
}


实体注释位于
javax.persistence
库中。

重复我在问题中所说的,当在命令行上使用play命令运行时,测试成功运行。只有在IntelliJ JUnit run config中运行测试时才会出现此异常。我误读了您的帖子。我想你们说过你们已经在Intelli J中运行了测试,但当你们试图使用数据库进行更高级的测试时,它失败了。我不认为你的意思是你要做同样的测试。很明显,它在模型类上失败了。Java堆栈跟踪是直截了当的,我在我的问题中推测可能是运行play时发生的某种指令插入在我运行IntelliJ时不会发生。问题是:“我需要什么JVM参数或类路径或其他东西来让IntelliJ测试运行程序模拟游戏?”我只是不认为这是问题所在。我只是在Mac上用内置的TestRunner安装了IntelliJ,没有任何问题。你能发布一些代码吗?基于您链接到的线程,我将play-testrunner.jar添加到项目依赖项中。现在我从所有测试的编译器那里得到一个错误,我将用堆栈跟踪更新这个问题。你找到解决这个问题的方法了吗?当我现在真的想运行一个测试时,我必须启动play Web服务器或使用play auto test。不,这个问题仍然没有解决。据我所知,play对JVM有一些魔力,我不知道如何在IntelliJ test runner中进行复制(可能根本不可能)。