mtkopone / scct

Scala Code Coverage Tool
http://mtkopone.github.com/scct/
Apache License 2.0
129 stars 39 forks source link

does sbt-scct support running test outside of scala project against instrumented classes? #62

Open daiq opened 11 years ago

daiq commented 11 years ago

Looks I have to put test under scala project hierarchy tree. What if the test is not written in scala or java, neither does it use any Scala main testing framework and sit outside of the tree? What are the steps to follow in that case? Is there any step like to allow first, compile source code with scct-sbt, so that tests outside of scala project run against the instrumented source?

daiq commented 11 years ago

Update it myself. Tried for standard code, running test still required source code to be in the classpath even though instrumented classes are already there. Is this by design and required to get the report?

C:\ScalaExamples\standard_proj_819_test>scala -cp ".;scct_2.9.2-0.2-SNAPSHOT.jar" com.autodesk.my.MyTestObject HELLO scct: [default] Generating coverage report. Exception in thread "Thread-0" java.io.FileNotFoundException: C:\ScalaExamples\standard_proj_819_test\MainObject.scala (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:120) at scala.io.Source$.fromFile(Source.scala:91) at scala.io.Source$.fromFile(Source.scala:76) at scala.io.Source$.fromFile(Source.scala:81) at reaktor.scct.report.SourceLoader.linesFor(SourceLoader.scala:8) at reaktor.scct.report.SourceFileHtmlReporter$.report(SourceFileHtmlReporter.scala:11) at reaktor.scct.report.HtmlReporter$$anonfun$sourceFileReports$2.apply(HtmlReporter.scala:92) at reaktor.scct.report.HtmlReporter$$anonfun$sourceFileReports$2.apply(HtmlReporter.scala:91) at scala.collection.immutable.TreeMap$$anonfun$foreach$1.apply(TreeMap.scala:160) at scala.collection.immutable.RedBlack$NonEmpty.foreach(RedBlack.scala:164) at scala.collection.immutable.TreeMap.foreach(TreeMap.scala:160) at reaktor.scct.report.HtmlReporter.sourceFileReports(HtmlReporter.scala:91) at reaktor.scct.report.HtmlReporter.report(HtmlReporter.scala:20) at reaktor.scct.Coverage$.report(Coverage.scala:58) at reaktor.scct.Coverage$$anon$1.run(Coverage.scala:67)

daiq commented 11 years ago

Continuing with the original question, I created a Play project and a junit test in scala which in turns calls a SoapUI test (test one GET api). I used scct:test to run the test and the soapui test runs and passed. However, the code coverage date shows 0% coverage which I observed from zero increase with other non-soapui junit test.

C:\ScalaExamples\PlayAppTestScala\todolist>sbt scct:test

C:\ScalaExamples\PlayAppTestScala\todolist>set SCRIPT_DIR=C:\Program Files (x86)\sbt\

C:\ScalaExamples\PlayAppTestScala\todolist>java -Xmx512M -XX:PermSize=128m -jar "C:\Program Files (x86)\sbt\sbt-launch.jar" scct:test [info] Loading project definition from C:\ScalaExamples\PlayAppTestScala\todolist\project [info] Set current project to todolis (in build file:/C:/ScalaExamples/PlayAppTestScala/todolist/) [info] Compiling 1 Scala source to C:\ScalaExamples\PlayAppTestScala\todolist\target\scala-2.10\scct-test-classes... [info] test.JunitTest soapUI 4.5.2 TestCase Runner 18:02:45,407 WARN [SoapUI] Missing folder [C:\ScalaExamples\PlayAppTestScala\todolist.\ext] for external libraries 18:02:45,408 INFO [DefaultSoapUICore] Creating new settings at [C:\Users\daiq\soapui-settings.xml] 18:02:46,656 INFO [WsdlProject] Loaded project from [file:/C:/ScalaExamples/PlayAppTestScala/todolist/test/TestMyExampleSoapUI-soapui-project.xml] 18:02:47,474 INFO [SoapUITestCaseRunner] Running soapUI tests in project [TestMyExampleSoapUI] 18:02:47,475 INFO [SoapUITestCaseRunner] Running TestSuite [TestSuite 1], runType = SEQUENTIAL 18:02:47,485 INFO [SoapUITestCaseRunner] Running soapUI testcase [TestCase 1] 18:02:47,498 INFO [SoapUITestCaseRunner] running step [HTTP Test Request] 18:02:47,713 INFO [SoapUITestCaseRunner] Assertion [Valid HTTP Status Codes] has status VALID 18:02:47,714 INFO [SoapUITestCaseRunner] Finished running soapUI testcase [TestCase 1], time taken: 103ms, status: FINISHED 18:02:47,715 INFO [SoapUITestCaseRunner] TestSuite [TestSuite 1] finished with status [FINISHED] in 234ms [info] + test.JunitTest.test [info] + test.JunitTest.testSay [info] [info] [info] Total for test test.JunitTest [info] Finished in 2.815 seconds [info] 2 tests, 0 failures, 0 errors [info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0 scct: [todolis] Generating coverage report. [success] Total time: 8 s, completed Aug 22, 2013 6:02:48 PM