Running Spec2 Unit test case from eclipse

In this article I’ll give some quick hints about how you can run your Scala unit test cases written using Spec2 from eclipse.

Writing unit test cases is fun and important aspect of any application where quality is important and large groups/teams are working on different parts of application.

You may want to run unit test cases directly from editor where you are writing test cases. Almost every other editor support execution of Java Junit test cases from eclipse.

When you are working with Scala code based you may want to write unit test cases using Spec2 and want to run directly from eclipse. As such you cannot do with making additional changes to test cases; here are the changes that you’ll have to add to your test cases so that you can run them from eclipse:

1)    Add below import statements to you Unit test class
import org.junit.runner.RunWith
import org.specs2.runner.{JUnitRunner}

2)    Annotate your test class with following annotation:

Now if you right click on your test case class you should see an option to execute your test case (Right click on test class -> Run As -> Scala Unit Test)

Hope this’ll help you to save some time while writing test cases.


Popular posts from this blog

Sling Authentication

CQ Development - OSGi bundles and Components

Create an AEM (CQ) project using Maven

Multiple log files using log4j appender