gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:11:55 25 4
gpt4 key购买 nike

我一直在尝试直接从内置测试运行器中运行 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 auto-test 中运行良好。

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

  • -javaagent:/home/sindrit/play-1.2.3/framework/play-1.2.3.jar
  • -Dfile.encoding=utf-8
  • -Dplay.debug=yes
  • -Dplay.id=test
  • -Dapplication.path=/home/sindrit/projects/testapp

这里有人让这个工作吗?

我需要哪些 JVM 参数或类路径或其他东西才能使 IntelliJ 测试运行器模拟游戏运行时环境?

如果我将 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)

最佳答案

我可能过度简化了这一点,但您似乎忘记了数据库模型上的实体注释。

您的模型应如下所示。

@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;
}

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

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

关于junit - 作为 IntelliJ IDEA JUnit 运行配置运行 playframework 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7810741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com