目次

Version 3, last updated by Heiko Seeberger at Apr 08 18:50 UTC

One way to test your Lift app is to manipulate it via a Scala console (REPL). Both Maven and SBT offer consoles that include your app and all dependencies within its classpath, making it easy to test bits of logic.

Launching the Console

From Maven:

$ mvn scala:console
...
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala>

From SBT:

$ sbt
...
> console
...
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala>

quit or Ctrl+D will exit the Scala console in both cases.

Using the Console

From your console you can import Lift modules and your own code. For example:

scala> import net.liftweb.common.{Box, Empty, Full}
import net.liftweb.common.{Box, Empty, Full}
scala> Full("something")
res0: net.liftweb.common.Full[java.lang.String] = Full(something)

Probably your first console command, however, should be to execute the code that you’ve included in Boot.scala to setup your app:

scala> new bootstrap.liftweb.Boot().boot

This is by no means necessary but is required if you’re using Mapper or Record and want to do a database operation during your console session.