想要对maven-lift-eclipse原型生成的默认Lift片段类进行简单的单元测试。
我称之为HelloWorld.scala
(project/src/main/scala/my/namespace/helloworld/snippet/HelloWorld.scala
)
package my.namespace.helloworld {
package snippet {
import _root_.scala.xml.NodeSeq
import _root_.net.liftweb.util.Helpers
import _root_.java.util.Date
import Helpers._
class HelloWorld {
def howdy(in: NodeSeq): NodeSeq =
Helpers.bind("b", in, "time" -> (new Date).toString)
}}}
所以我添加了一个新测试testHowdy
,添加到默认生成的AppTest.scala
(project/src/test/scala/my/namespace/AppTest.scala
}
package my.namespace
import _root_.java.io.File
import _root_.junit.framework._
import Assert._
import _root_.scala.xml.XML
import _root_.net.liftweb.util._
import _root_.net.liftweb.common._
import my.namespace._
object AppTest {
def suite: Test = {
val suite = new TestSuite(classOf[AppTest])
suite
}
def main(args : Array[String]) {
_root_.junit.textui.TestRunner.run(suite)
}
}
/**
* Unit test for simple App.
*/
class AppTest extends TestCase("app") {
/**
* Rigourous Tests :-)
*/
def testOK() = assertTrue(true)
// def testKO() = assertTrue(false);
def testHowdy() = {
val h = new HelloWorld()
assertFalse(h.howdy("<!DOCTYPE html><title></title><p><b:time></p>") contains "")
}
def testXml() = {
<snip>
}
}
通过该附加测试,我生成了运行$ mvn test
的编译错误:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld Project
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [resources:copy-resources {execution: default-copy-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] [yuicompressor:compress {execution: default}]
[INFO] nb warnings: 0, nb errors: 0
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [scala:compile {execution: default}]
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [scala:testCompile {execution: default}]
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] /home/noel/workspace/helloworld/src/test/scala:-1: info: compiling
[INFO] Compiling 2 source files to /home/noel/workspace/helloworld/target/test-classes at 1301433670806
[ERROR] /home/noel/workspace/helloworld/src/test/scala/my/namespace/helloworld/AppTest.scala:34: error: not found: type HelloWorld
[INFO] val h = new HelloWorld()
[INFO] ^
[ERROR] one error found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1(Exit value: 1)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14 seconds
[INFO] Finished at: Tue Mar 29 16:21:18 CDT 2011
[INFO] Final Memory: 25M/61M
[INFO] ------------------------------------------------------------------------
这似乎是某种简单的命名空间问题,但我无法追踪我导入错误的位置!
注意:默认生成的AppTest.scala确实成功运行。它只是在我的额外测试后才开始编译。
答案 0 :(得分:1)
我似乎无法找到你所做的那些意味着......
import my.namespace.helloworld.snippet.HelloWorld