From 8cba83aebb232b5d787e098c1781346ed21f67bd Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Mon, 3 Dec 2018 18:08:21 -0800 Subject: [PATCH] Improve TestFramework error reporting It is possible for the test task to fail because of issues with the layered ClassLoaders. When this occurs and is detectable, I try to provide a useful error message that will help the user fix the issue. --- testing/src/main/scala/sbt/TestFramework.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/testing/src/main/scala/sbt/TestFramework.scala b/testing/src/main/scala/sbt/TestFramework.scala index ad8b8d91f..d06f95c42 100644 --- a/testing/src/main/scala/sbt/TestFramework.scala +++ b/testing/src/main/scala/sbt/TestFramework.scala @@ -46,6 +46,17 @@ final class TestFramework(val implClassNames: String*) extends Serializable { log: ManagedLogger, frameworkClassNames: List[String] ): Option[Framework] = { + def logError(e: Throwable): Option[Framework] = { + log.error( + s"Error loading test framework ($e). This usually means that you are" + + " using a layered class loader that cannot reach the sbt.testing.Framework class." + + " The most likely cause is that your project has a runtime dependency on your" + + " test framework, e.g. scalatest. To fix this, you can try to set\n" + + "Test / layeringStrategy := new LayeringStrategy.Test(false, true)\nor\n" + + "Test / layeringStrategy := LayeringStrategy.Flat" + ) + None + } frameworkClassNames match { case head :: tail => try { @@ -54,6 +65,8 @@ final class TestFramework(val implClassNames: String*) extends Serializable { case oldFramework: OldFramework => new FrameworkWrapper(oldFramework) }) } catch { + case e: NoClassDefFoundError => logError(e) + case e: MatchError => logError(e) case _: ClassNotFoundException => log.debug("Framework implementation '" + head + "' not present.") createFramework(loader, log, tail)