2015-01-27 9 views
10

के साथ जुनीट परीक्षण चलाएं मेरे पास कई उप-परियोजनाओं के साथ 0.13.7 एसबीटी परियोजना है।एसबीटी

उनमें से एक को webapp कहा जाता है, और इसमें webapp/src/test/java में कई JUnit परीक्षण हैं।

जब चल रहा है:

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)); 
    } 
} 

अद्यतन (कुछ और अधिक शोध):

> 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 समर्थन से जाना जाता है एसबीटी लेकिन लोड नहीं ईडी।

डिबग आउटपुट:

[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,[email protected])) 
[debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,[email protected])) 
[debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,[email protected])) 

के साथ कार्य करना:

  • एसबीटी 0.13.9, और
  • JUnit 4.x.

संबंधित जानकारी:

उत्तर

8

अंत में, मुझे पता चला है, मैं subproject के लिए निम्न सेटिंग जोड़ने के लिए है:

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 निर्भरता घोषित करना महत्वपूर्ण है, और इसके अतिरिक्त, crossPaths सेटिंग को झूठी सेट करने के लिए।

सुराग this issue द्वारा दिया गया है।

यदि मुख्य प्रोजेक्ट में JUnit परीक्षण नहीं हैं, तो आवश्यक परीक्षण सेटिंग्स, प्रदान करने की आवश्यकता नहीं है।

इसके अलावा, में नाकाम रहने के विधि और कारण जानने के लिए, हम इस सेटिंग की जरूरत है:

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

वहाँ crossPaths में कोई गलती है (crossPathts), लेकिन इतना की अनुमति नहीं है मुझे छोटे संपादन –

+0

धन्यवाद @checat, टाइपो को सही किया। –