本文介绍了Play 2.0-从Scala控制台访问正在运行的(Fake)应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Play Framework 2.0(使用当前主干2.1-SNAPSHOT,Scala),并且发现在play console中尝试使用Scala API非常有用.

I'm just getting started with the Play Framework 2.0 (using current trunk 2.1-SNAPSHOT, Scala) and I'm finding it very useful to experiment with the Scala API in the play console.

但是,对于某些事情,例如依赖于play.libs.WS API的东西,我遇到了There is no started application错误.足够公平,但是我不知道如何设置一个可从控制台使用的假冒产品,或者这是否有可能.

For some things, however, for example stuff that depends on play.libs.WS API, I'm getting the There is no started application error. Fair enough, but I can't figure out how to set up a fake one up to use from the console, or whether this is even possible.

似乎甚至无法从控制台访问play.api.test._.有什么建议吗?

It seems that play.api.test._ isn't even accessible from the console. Any suggestions?

更新:感谢@charroch,我需要运行play test:console,所以我现在可以这样做:

Update: Thanks to @charroch, I needed to run play test:console, so I can now do:

import play.api.test.Helpers.running
import play.api.test.FakeApplication

val res = running(FakeApplication()) { 
    MyWebservice.someFunction()  
}

推荐答案

尝试test:console使用类路径中的测试api启动控制台

try test:console to start the console with test api in classpath

您需要按照以下步骤在测试中使用running(FakeApplication) {...}: http://www.playframework.org/documentation/2.0/ScalaTest

You need to have running(FakeApplication) {...} in your test as per:http://www.playframework.org/documentation/2.0/ScalaTest

这篇关于Play 2.0-从Scala控制台访问正在运行的(Fake)应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:49