我正在为 Web 应用程序编写单元测试并使用 Java Play!(2.1.3) 框架的 FakeApplication 类。
public class TagTest {
public static FakeApplication app;
...
// BeforeClass only runs once before any tests are run
@BeforeClass
public static void setUpBeforeClass() {
// Set up new FakeApplication before running any tests
app = Helpers.fakeApplication(Helpers.inMemoryDatabase());
Helpers.start(app);
}
...
}
我在所有四个测试类中都有相同的 setUpBeforeClass() 方法来测试我的四个不同模型中的每一个,但是当我运行play test命令时,所有四个测试类都返回类似的错误:
[error] Test models.TagTest failed: java.lang.NullPointerException: null
[error] at Global.onStart(Global.java:59)
[error] at play.core.j.JavaGlobalSettingsAdapter.onStart(JavaGlobalSettingsAdapter.scala:17)
[error] at play.api.GlobalPlugin.onStart(GlobalSettings.scala:175)
[error] at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:68)
[error] at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:68)
[error] at scala.collection.immutable.List.foreach(List.scala:309)
[error] at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:68)
[error] at play.api.Play$$anonfun$start$1.apply(Play.scala:68)
[error] at play.api.Play$$anonfun$start$1.apply(Play.scala:68)
[error] at play.utils.Threads$.withContextClassLoader(Threads.scala:18)
[error] at play.api.Play$.start(Play.scala:67)
[error] at play.api.Play.start(Play.scala)
[error] at play.test.Helpers.start(Helpers.java:354)
[error] at models.TagTest.setUpBeforeClass(TagTest.java:35)
其中第 35 行是该行:
Helpers.start(app);
我在这里做错了吗?