Monday, March 12, 2012

Code Coverage Results


Code coverage results for the examples discussed in the Accurate programming  by Prof.Veronica Gaspes, Prof.Rex Page, Prof. Walid Taha







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.....







Creating a new project and its definition in SBT - Ubuntu 11.10

Credit goes to the original publishers...
I modified or organized the original content...
Before creating a new project the sbt  should be setup to launch it from any directory. To do it follow the [2-5] for Ubuntu 11.10



1. Choose your own directory to create a new project
2. Using Terminal, enter into the directory where you planned to create a new project
3. Type sbt into the terminal, if the sbt launch is set properly, you see the below image content



4.It will ask you, create a new project? (y/N/s)  Type y and press enter

5. The project has been successfully created, you can check it by visiting the directory where you created the new project, You could see the four folders as shown in the right side of the top image.

6. let us start with an example code, to test if our new project works fine. Copy the below code to the directory  src\main\scala

   object Anil{
         def main(args:Array[String]){
           println("\n\n Hello Anil, You program has been successfully Executed \n\n ")
         } 
    }





7. From Terminal go to directory
8. Type sbt and press enter.
9. Type reload and press enter.
10.Type update and press enter.
11. Type run and press enter.
If everything goes fine you could see the output displayed in blow image 


12. Configure sbt by creating project definition using a scala file in to the directory  project\build\MyFirstProject.scala

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





13. Type hi in command prompt, you will see...



By now, You know how to create a new project, configure SBT by creating a project definition, program an example in Scala and successfully execute it.
Good Luck with the rest.
enjoy the rest of your journey with Scala using SBT

Saturday, March 3, 2012

Unit Testing- Scala Code Coverage Tool - SCCT Windows 7


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. Add the following code to (In my case) C:\Users\anil\anil\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(Inmycase)  C:\Users\anil\anil\project\build\AnilFirstProject.scala , should extent reaktor.scct.ScctProject


import sbt._
import reaktor.scct.ScctProject
class HelloAnilProject(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 (In my case) c:\Users\anil\anil\
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 test-coverage and press enter.
if everything goes fine you see below output
8. To check the test output open /target/scala_2.9.1/coverage-report/index.html

enjoy.....






Creating a new project and its definition in SBT - Windows 7

Credit goes to the original publishers...
I modified or organized the original content...
Before creating a new project the sbt  should be setup to launch it from any directory. To do it follow the [2-5] for Windows 7



1. Choose your own directory to create a new project
2. Using Command prompt, enter into the directory where you planned to create a new project
3. Type sbt at the command prompt, if the sbt launch is set properly, you see the below image content in the command prompt

4.It will ask you, create a new project? (y/N/s)  Type y and press enter
5. The project has been successfully created, you can check it by visiting the directory where you created the new project, you could see  the folder that you can see in the below image.
6. let us start with an example code, to test if our new project works fine. Copy the below code to the directory (In my case) C:\Users\anil\anil\src\main\scala

   object Anil{
         def main(args:Array[String]){
           println("\n\n Hello Anil, You program has been successfully Executed \n\n ")
         } 
    }

7. From command prompt go to directory (In my case) c:\Users\anil\anil
8. Type sbt and press enter.
9. Type relosd and press enter.
10.Type update and press enter.
11. Type run and press enter.
If everything goes fine you could see the output displayed in blow image 

12. Configure sbt by creating project definition using a scala file in to the directory (In my case) c:\Users\anil\anil\project\build\AnilFirstProject.scala

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


13. Type hi in command prompt, you will see...

By now, You know how to create a new project, configure SBT by creating a project definition, program an example in Scala and successfully execute it.
Good Luck with the rest.
enjoy the rest of your journey with Scala using SBT