Bu Blogda Ara

28 Eylül 2010 Salı

Integrated Mockito TestNG and Emma on an ant built (Targeted for Java developers who aim TDD)

I have prepared a very simple sample ant project showing how to integrate and run Mockito, TestNG and Emma projects. For those of you who wonder what these projects are, Mockito is Java Mock framework, TestNG is Unit Test Case Framework and Emma is the code test coverage tool.

The purpose of this project is to demonstrate how ClassThatOutputsHelloMessage is tested with TestNG. How NameProviderInterface is mocked with Mockito and how is the Mockito syntax written in TestNG test case. Showing dependency injection = Giving NameProviderInterface as ClassThatOutputsHelloMessage constructor argument. And what kind of code coverage report you obtain with emma.

Inorder to see the sample checkout my experimental stuff rep with hg(mercurial client)

hg clone https://barisergunexperimentalstuff.googlecode.com/hg/ barisergunexperimentalstuff

And than, navigate to testngmockitosimplesample folder. And run the below ant command:

ant runtestswithemma

If everything is okey you will see a generated folder named coverage. Inside this directory you will see 3 different formats of report(html,xml,txt). Especially check the html format to easily navigate the report to see which lines of code is not tested.

At the begining you will see that not all of the code is tested. In the ClassThatOutputsHelloMessageTest.java source Uncomment the commented-out test case. And re-run tests with emma. Check and verify that the coverage report has changed with %100 coverage.

Please place a comment here on this blog if you face any problems.

Things to remember:

Make sure your environment variable JAVA_HOME is set. When you try to integrate these tools to your own project keep in mind that you should compile your sources with debug="on" option in order to be able to see the line coverage of your codes with emma instrumentation.


Blogs that helped me:
http://rwatsh.blogspot.com/2008/03/using-testng-with-emma-for-automating.html

1 yorum:

  1. Hi, i am using junit+mockito. Emma is not showing coverage for mockito. is there any configuration that needs to be done
    for this?

    YanıtlaSil