Sunday, March 4, 2012

Unit Testing- Scala Code Coverage Tool - SCCT -SBT- ScalaCheck- Ubuntu 11.10


Credit goes to the original publishers...
http://mtkopone.github.com/scct/
I modified or organized the original content...

After Creating a New Project now its time for the Code Coverage Analysis setup using the SCCT. All the instructions about the SCCT setup were given by the original publisher. I would like to give you a detailed step level setup explanation which makes your path easy for setup.
Set up for SCCT tool.
1. Create plugins folder as shown in below image.





Add the following code to project\plugins\Plugins.scala


import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val scctRepo = "scct-repo" at "http://mtkopone.github.com/scct/maven-repo/"
 lazy val scctPlugin = "reaktor" % "sbt-scct-for-2.8" % "0.1-SNAPSHOT"
}  





2. Project definition \project\build\MyFirstProject.scala , should extent reaktor.scct.ScctProject


import sbt._
import reaktor.scct.ScctProject
class AnilsProject(info: ProjectInfo) extends DefaultProject(info) with ScctProject
{
lazy val hi=task {println("This is Anils First New Project"); None}
}



3. Enter in to the project directory
4. Type sbt and press enter


5. Type reload and press enter (necessary only when code is changed or some new files added)
 6. Type update and  press enter(only when code is changed or some new files added)


7. Type run and press enter.


8. Type test-coverage and press enter
if everything goes fine you see below output


Surprising, Its says that there are no tests to run. Its right we did not write any code for test until now.
9. Add the below code to the file project/build/MyFirstProject.scala
val scalaTest = "org.scalatest" % "scalatest" % "1.2"
  val scalaCheck = "org.scala-tools.testing" % "scalacheck_2.8.0" % "1.7"

10. Update source code  src/main/scala
11. Update source code for test in src/test/scala


12. now go to terminal type , reload and enter, update and enter
13. Type test-coverage and press enter.


14. To check the test output open /target/scala_2.8.1/coverage-report/index.html



 

It wasted me a lot of time in setting up the interface to run simple tests. there is no any written manual for the new bees to guide through the process. This struggle with all these setup inspired me to present a guide for the persons who are new to use Scala, SBT, ScalaCheck, SCCT,  




enjoy.....







2 comments:

  1. Thank you so much, Its really very helpful to me.
    Keep it up !

    Anuj

    ReplyDelete
  2. Hi ,Can you have any idea , how we run a single test by SCCT as we run by Junit "test-only"

    Thanks
    Anuj

    ReplyDelete