java.lang.NoClassDefFoundError:执行ScalaTest测试时的sbt / testing / Framework?

时间:2014-06-17 04:03:28

标签: 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 version:0.13.2

项目/ build.properties

sbt.version=0.13.2

项目/ 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")

项目/ 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"))

}

0 个答案:

没有答案