无法运行“mvn clean test”使用scalatest
我正在学习如何使用 ScalaTest。
现在我在 JetBrains IDEA 中使用 scala 2.11.8。
首先,我编写了一个简单的特征traitA
。
package Cha1_TraitsAndMixinCompositions.Clash
trait A {
def hello(): String = "Hello, I am trait A!"
def pass(a: Int): String = s"Trait A said: 'You passed $a.'"
}
然后我编写了一个测试文件 TraitASpec.scala
:
import Cha1_TraitsAndMixinCompositions.Clash.A
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class TraitASpec extends AnyFlatSpec with Matchers with A {
"hello" should "greet properly." in {
hello() should equal("Hello, I am trait A!")
}
}
当我单击绿色按钮时,它工作正常。 单击绿色按钮
但是当我运行命令mvn clean test
时,出了问题:
[INFO] compiling 4 Scala sources to /Users/yangdaichuan/Desktop/gitlab/SparkGraphX/target/test-classes ...
[ERROR] /Users/yyy/Desktop/gitlab/SparkGraphX/src/test/scala/TraitASpec.scala:1: not found: object Cha1_TraitsAndMixinCompositions
[ERROR] /Users/yyy/Desktop/gitlab/SparkGraphX/src/test/scala/TraitASpec.scala:5: not found: type A
[ERROR] /Users/yyy/Desktop/gitlab/SparkGraphX/src/test/scala/TraitASpec.scala:7: not found: value hello
[ERROR] three errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.812 s
[INFO] Finished at: 2022-03-02T14:13:23+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.5.6:testCompile (default) on project Spark2Learn: Execution default of goal net.alchim31.maven:scala-maven-plugin:4.5.6:testCompile failed: Compilation failed: InterfaceCompileFailed -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
如果我删除这个 TraitASpec.scala
,然后运行 mvn clean test
它工作正常。
顺便说一句,当我遵循 ScalaTest 用户指南 并编写了一个像 StackSpec.txt 这样的测试文件时。 scala
:
import collection.mutable.Stack
import org.scalatest.flatspec.AnyFlatSpec
class StackSpec extends AnyFlatSpec {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
assert(stack.pop() === 2)
assert(stack.pop() === 1)
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[String]
assertThrows[NoSuchElementException] {
emptyStack.pop()
}
}
}
并运行 mvn clean test
它有效。
我猜文件结构或代码路径有问题?
你能帮助我吗?谢谢你!
I'm learnning how to use ScalaTest.
now I'm using scala 2.11.8, in JetBrains IDEA.
Fisrt I wrote a simple trait traitA
.
package Cha1_TraitsAndMixinCompositions.Clash
trait A {
def hello(): String = "Hello, I am trait A!"
def pass(a: Int): String = s"Trait A said: 'You passed $a.'"
}
then I wrote a test file TraitASpec.scala
:
import Cha1_TraitsAndMixinCompositions.Clash.A
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class TraitASpec extends AnyFlatSpec with Matchers with A {
"hello" should "greet properly." in {
hello() should equal("Hello, I am trait A!")
}
}
when I click the green button it works fine.
click green button
But when I run a command mvn clean test
,somethings wrong:
[INFO] compiling 4 Scala sources to /Users/yangdaichuan/Desktop/gitlab/SparkGraphX/target/test-classes ...
[ERROR] /Users/yyy/Desktop/gitlab/SparkGraphX/src/test/scala/TraitASpec.scala:1: not found: object Cha1_TraitsAndMixinCompositions
[ERROR] /Users/yyy/Desktop/gitlab/SparkGraphX/src/test/scala/TraitASpec.scala:5: not found: type A
[ERROR] /Users/yyy/Desktop/gitlab/SparkGraphX/src/test/scala/TraitASpec.scala:7: not found: value hello
[ERROR] three errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.812 s
[INFO] Finished at: 2022-03-02T14:13:23+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.5.6:testCompile (default) on project Spark2Learn: Execution default of goal net.alchim31.maven:scala-maven-plugin:4.5.6:testCompile failed: Compilation failed: InterfaceCompileFailed -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
and if I delete this TraitASpec.scala
,then run mvn clean test
it works fine.
BTW, when I follow the ScalaTest User Guide and wrote a test file like StackSpec.scala
:
import collection.mutable.Stack
import org.scalatest.flatspec.AnyFlatSpec
class StackSpec extends AnyFlatSpec {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
assert(stack.pop() === 2)
assert(stack.pop() === 1)
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[String]
assertThrows[NoSuchElementException] {
emptyStack.pop()
}
}
}
and run mvn clean test
it worked.
I guess there is something wrong with the file stucture or code path?
Can you help me? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在配置/设置中检查工作目录是什么。将其设置为模块路径。
还可以尝试使/清除缓存无效并重新启动,它会再次选择文件。
In the configuration/Setting check what is the working directory . Set it to the module path.
Also try invalidating /clear cache and Restart, It picks the files again.