开发者

Scala Lift JUnit Test Fails With "error: not found: type foo" Using mvn test

开发者 https://www.devze.com 2023-02-20 10:46 出处:网络
Wanted to do a simple unit test of the default Lift开发者_JAVA技巧 snippet class generated by the maven-lift-eclipse archetype.

Wanted to do a simple unit test of the default Lift开发者_JAVA技巧 snippet class generated by the maven-lift-eclipse archetype.

I called it HelloWorld.scala (in 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)
}}}

So I added added a new test, testHowdy, to the default generated AppTest.scala (in 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>
  }
}

With that additional test, I generate a compile error running $ 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] ------------------------------------------------------------------------

This seems like a simple namespace issue of some sort, but I can't track down where I'm doing the import wrong!

Note: the default generated AppTest.scala does run successfully. It only started failing to compile after my additional test.


I can't seem to find any import you do that implies...

import my.namespace.helloworld.snippet.HelloWorld
0

精彩评论

暂无评论...
验证码 换一张
取 消