2015-01-27 3 views
10

У меня есть проект 0.13.7 SBT с несколькими подпроектами.Запуск тестов JUnit с SBT

Один из них называется webapp, и он имеет множество JUnit тестов в webapp/src/test/java.

Когда не работает:

sbt webapp/test 

только ScalaTest тесты запускаются, но не JUnit тесты.

Отрывок из моего build.sbt файла:

libraryDependencies ++= Seq(
    "com.novocode" % "junit-interface" % "0.11" % Test 
) 

lazy val webapp = project 
    settings(
     Seq(
      projectDependencies ++= Seq(
       .... 
       "org.scalatest" %% "scalatest" % "2.2.2" % Test, 
       "junit" % "junit" % "4.11" % Test, 
       "com.novocode" % "junit-interface" % "0.11" % Test 
      ) 
     ): _* 
    ) 

Пример JUnit тест:

import org.junit.Test; 

public class CodificadorBase64Test { 
    @Test 
    public void testPlain() { 
     byte b[] = {64, 127, 72, 36, 100, 1, 5, 9, 123}; 
     assertEquals("QH9IJGQBBQl7", CodificadorBase64.encode(b)); 
    } 
} 

UPDATE (некоторые дополнительные исследования):

> webapp/testFrameworks 
[info] List(TestFramework(WrappedArray(org.scalacheck.ScalaCheckFramework)), TestFramework(WrappedArray(org.specs2.runner.Specs2Framework, org.specs2.runner.SpecsFramework)), TestFramework(WrappedArray(org.specs.runner.SpecsFramework)), TestFramework(WrappedArray(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)), TestFramework(WrappedArray(com.novocode.junit.JUnitFramework)) 

show webapp/loadedTestFrameworks 
[info] Map(TestFramework(WrappedArray(
    org.scalatest.tools.Framework, 
    org.scalatest.tools.ScalaTestFramework) 
) -> [email protected]) 

Так поддержка JUnit известна SBT, но не загружается редактор

выход

Debug:

[debug] Framework implementation 'org.scalacheck.ScalaCheckFramework' not present. 
[debug] Framework implementation 'org.scalacheck.ScalaCheckFramework' not present. 
[debug] Framework implementation 'org.scalacheck.ScalaCheckFramework' not present. 
[debug] Framework implementation 'org.scalacheck.ScalaCheckFramework' not present. 
[debug] Framework implementation 'org.specs2.runner.Specs2Framework' not present. 
[debug] Framework implementation 'org.specs2.runner.Specs2Framework' not present. 
[debug] Framework implementation 'org.specs2.runner.Specs2Framework' not present. 
[debug] Framework implementation 'org.specs2.runner.Specs2Framework' not present. 
[debug] Framework implementation 'org.specs2.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs2.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs2.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs2.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs.runner.SpecsFramework' not present. 
[debug] Framework implementation 'org.specs.runner.SpecsFramework' not present. 
[debug] Framework implementation 'com.novocode.junit.JUnitFramework' not present. 
[debug] Framework implementation 'com.novocode.junit.JUnitFramework' not present. 
[debug] Framework implementation 'com.novocode.junit.JUnitFramework' not present. 
[debug] Framework implementation 'com.novocode.junit.JUnitFramework' not present. 
[debug] Subclass fingerprints: List((org.scalatest.Suite,false,[email protected])) 
[debug] Subclass fingerprints: List((org.scalatest.Suite,false,[email protected])) 
[debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,[email protected])) 
[debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,[email protected])) 
[debug] Subclass fingerprints: List((org.scalatest.Suite,false,[email protected])) 
[debug] Subclass fingerprints: List((org.scalatest.Suite,false,org.scalates[email protected])) 
[debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,[email protected])) 
[debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,[email protected])) 

Работа с:

  • SBT 0.13.9 и
  • JUnit 4.x.

Сопутствующая информация:

ответ

8

Наконец, я обнаружил, что я должен добавить следующие параметры подпроекта:

lazy val webapp = project 
    settings(
     Seq(
      projectDependencies ++= Seq(
       .... 
       "org.scalatest" %% "scalatest" % "2.2.2" % Test, 
       "junit" % "junit" % "4.11" % Test, 
       crossPaths := false, 
       "com.novocode" % "junit-interface" % "0.11" % Test 
      ) 
     ): _* 
    ) 

Важно объявить зависимость junit-interface в подпроекте и, кроме того, установить значение false crossPaths.

Ключ предоставлен this issue.

Если в главном проекте нет тестов JUnit, то необходимые настройки теста не обязательно должны предоставляться.

Кроме того, для познания метода неисправного и причины, нам нужен этот параметр:

testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a")) 
+1

есть опечатка в crossPaths (crossPathts), но ТАК не позволяет мне небольшие правки –

+0

Благодаря @checat, исправил опечатку. –

Смежные вопросы