#scala #sbt #scalatest
#scala #sbt #scalatest
Вопрос:
Я использую ScalaTest в качестве своей платформы тестирования.
build.sbt
import com.typesafe.sbt.SbtStartScript
name := "myproject"
organization := "my.org"
version := "0.1"
scalaVersion := "2.11.0"
//Define dependencies. These ones are only required for Test and Integration Test scopes.
libraryDependencies = Seq(
"org.scalatest" %% "scalatest" % "2.1.7" % "test,it",
"org.scalacheck" %% "scalacheck" % "1.11.4" % "test,it",
"com.typesafe.akka" %% "akka-actor" % "2.3.3",
"org.scala-lang" % "scala-swing" % "2.11.0-M7",
"commons-io" % "commons-io" % "2.4"
)
// For Settings/Task reference, see http://www.scala-sbt.org/release/sxr/sbt/Keys.scala.html
// Compiler settings. Use scalac -X for other options and their description.
// See Here for more info http://www.scala-lang.org/files/archive/nightly/docs/manual/html/scalac.html
scalacOptions = List("-feature","-deprecation", "-unchecked", "-Xlint")
// ScalaTest settings.
// Ignore tests tagged as @Slow (they should be picked only by integration test)
testOptions in Test = Tests.Argument(TestFrameworks.ScalaTest, "-l", "org.scalatest.tags.Slow", "-u","target/junit-xml-reports", "-oD", "-eS")
//Style Check section
org.scalastyle.sbt.ScalastylePlugin.Settings
org.scalastyle.sbt.PluginKeys.config <<= baseDirectory { _ / "src/main/config" / "scalastyle-config.xml" }
// Generate Eclipse project with sources for dependencies
EclipseKeys.withSource := true
// For sbt-dependency-graph
net.virtualvoid.sbt.graph.Plugin.graphSettings
Когда я пытаюсь запустить какой-либо из тестов, я вижу эту ошибку
> test
[trace] Stack trace suppressed: run 'last test:loadedTestFrameworks' for the full output.
[error] (test:loadedTestFrameworks) java.lang.NoClassDefFoundError: sbt/testing/Framework
[error] Total time: 0 s, completed Jun 17, 2014 11:53:00 AM
Ручной запуск теста в порядке
$ scala -cp ~/.ivy2/cache/org.scalatest/scalatest_2.11/jars/scalatest_2.11-2.1.7.jar org.scalatest.run my.org.myproject.StackSpec
Run starting. Expected test count is: 2
StackSpec:
A Stack
- should pop values in last-in-first-out order
- should throw NoSuchElementException if an empty stack is popped
Run completed in 169 milliseconds.
Total number of tests run: 2
Suites: completed 1, aborted 0
Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
Это полный путь к классу
sbt > show fullClasspath
[info] List(Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/target/scala-2.11/classes), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/ant-1.7.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/ant-launcher-1.7.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/antlr-2.7.7.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/aopalliance-1.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/asm-4.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/asm-all-4.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/asm-analysis-4.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/asm-tree-4.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/asm-util-4.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/bsh-2.0b4.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/cglib-nodep-2.2.2.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-codec-1.6.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-collections-3.2.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-exec-1.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-io-2.2.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-io-2.4.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-lang3-3.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/commons-logging-1.1.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/cssparser-0.9.9.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/easymock-3.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/easymockclassextension-3.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/guava-14.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/guice-2.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/hamcrest-core-1.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/hamcrest-library-1.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/htmlunit-2.12.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/htmlunit-core-js-2.12.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/httpclient-4.2.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/httpcore-4.2.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/httpmime-4.2.3.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jcommander-1.27.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jetty-http-8.1.9.v20130131.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jetty-io-8.1.9.v20130131.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jetty-util-8.1.9.v20130131.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jetty-websocket-8.1.9.v20130131.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jmock-2.5.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jmock-legacy-2.5.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/jna-3.4.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/json-20080701.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/junit-4.10.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/mockito-all-1.9.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/nekohtml-1.9.18.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/netty-3.5.2.Final.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/objenesis-1.2.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/parboiled-core-1.1.6.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/parboiled-java-1.1.6.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/pegdown-1.4.2.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/platform-3.4.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/sac-1.3.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scala-compiler-2.11.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scala-library-2.11.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scala-parser-combinators_2.11-1.0.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scala-reflect-2.11.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scala-xml_2.11-1.0.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalac-scoverage-plugin_2.11-0.99.5-javadoc.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalac-scoverage-plugin_2.11-0.99.5-sources.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalac-scoverage-plugin_2.11-0.99.5.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalacheck_2.11-1.11.3.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalacheck_2.11-1.11.4-javadoc.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalacheck_2.11-1.11.4-sources.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalacheck_2.11-1.11.4.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalatest_2.11-2.1.7-javadoc.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalatest_2.11-2.1.7-sources.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/scalatest_2.11-2.1.7.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-android-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-api-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-chrome-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-firefox-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-htmlunit-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-ie-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-iphone-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-java-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-remote-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-safari-driver-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/selenium-support-2.35.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/serializer-2.7.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/snakeyaml-1.12.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/stringtemplate-3.2.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/test-interface-1.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/testng-6.8.7.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/webbit-0.4.14.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/xalan-2.7.1.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/xercesImpl-2.10.0.jar), Attributed(/Users/hanxue/Code/Scala/entrypass-controller-simulator/lib/xml-apis-1.4.01.jar), Attributed(/Users/hanxue/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/jars/akka-actor_2.11-2.3.3.jar), Attributed(/Users/hanxue/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar), Attributed(/Users/hanxue/.ivy2/cache/com.typesafe/config/bundles/config-1.2.1.jar), Attributed(/Users/hanxue/.ivy2/cache/org.scala-lang/scala-swing/jars/scala-swing-2.11.0-M7.jar), Attributed(/Users/hanxue/.ivy2/cache/commons-io/commons-io/jars/commons-io-2.4.jar))
[success] Total time: 0 s, completed Jun 17, 2014 11:52:15 AM
Это дерево зависимостей теста
> test:dependency-tree
[info] net.entrypass:controller-simulator_2.11:0.1 [S]
[info] -com.typesafe.akka:akka-actor_2.11:2.3.3
[info] | -com.typesafe:config:1.2.1
[info] | -org.scala-lang:scala-library:2.11.1
[info] |
[info] -commons-io:commons-io:2.4
[info] -org.scala-lang:scala-library:2.11.1
[info] -org.scala-lang:scala-swing:2.11.0-M7
[info] | -org.scala-lang:scala-library:2.11.0-M7 (evicted by: 2.11.1)
[info] | -org.scala-lang:scala-library:2.11.1
[info] |
[info] -org.scalacheck:scalacheck_2.11:1.11.4 [S]
[info] | -org.scala-lang.modules:scala-parser-combinators_2.11:1.0.1 [S]
[info] | | -org.scala-lang:scala-library:2.11.1
[info] | |
[info] | -org.scala-lang:scala-library:2.11.1
[info] | -org.scala-sbt:test-interface:1.0
[info] |
[info] -org.scalatest:scalatest_2.11:2.1.7 [S]
[info] -org.scala-lang.modules:scala-parser-combinators_2.11:1.0.1 [S]
[info] | -org.scala-lang:scala-library:2.11.1
[info] |
[info] -org.scala-lang.modules:scala-xml_2.11:1.0.1 [S]
[info] | -org.scala-lang:scala-library:2.11.1
[info] |
[info] -org.scala-lang:scala-library:2.11.1
[info] -org.scala-lang:scala-reflect:2.11.0 [S]
[info] -org.scala-lang:scala-library:2.11.1
Я просмотрел ~/.ivy2/cache
, есть ли какие-либо конфликтующие библиотеки, и нашел ScalaTest 2.1.6. После удаления версии я все еще получаю ту же ошибку.
Как мне удалить java.lang.NoClassDefFoundError: sbt/testing/Framework
ошибку?
Примечание: пожалуйста, игнорируйте структуру каталогов. Изменение сделано для краткости.
Обновление 1
- Версия Scala (в
build.sbt
): 2.11.0 - версия sbt: 0.13.2
project /build.properties
sbt.version=0.13.2
project/plugins.sbt
resolvers = Classpaths.sbtPluginReleases
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "0.99.5")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.4.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.10.0")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4")
project/Build.scala
import sbt._
import Keys._
/**
* Additional configuration
*/
object Build extends Build {
lazy val integrationTest =
Project("root", file("."))
.configs( IntegrationTest )
.settings( Defaults.itSettings : _* )
.settings(
scalaSource in IntegrationTest <<= baseDirectory / "src/test/scala",
resourceDirectory in IntegrationTest <<= baseDirectory / "src/test/resources",
parallelExecution in IntegrationTest := false,
testOptions in IntegrationTest = Tests.Argument(TestFrameworks.ScalaTest, "-n", "org.scalatest.tags.Slow"))
}
Комментарии:
1. Я не могу воспроизвести ошибку — она просто работает на моей машине с вашими настройками. Возможно ли клонировать проект из github? Таким образом, мы могли бы устранить любые различия между средами друг друга.
2. sbt / testing / Framework взят из jar тестового интерфейса sbt, пахнет как проблема с версией sbt, какую версию sbt launcher вы используете?
3. Я не смог воспроизвести проблему, используя пример проекта, следующего за вашими файлами сборки: github.com/cheeseng/hanxue-debug