Version 4, last updated by pragprogger at March 31, 2011 13:35 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>
(If you get the error “[error] Error running compile: Compilation failed” when executing the “console” command, then first run the “update” command. This is required when using lift-lift_22_sbt-2.2-0-g22a67aa.zip (current))
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.