Open source: testcase-annotation

We can use @testcase to write test case for java methods and generate them to one excel and html.






Why write this tool

In traditional test process, we are familiar with writing test cases in excel at first and then to implement the test cases’ automation one by one. At last,we add the java doc to every test method.

The problem is that when we change the test cases in excel we should found where is the related test scripts and located the code and change the test case java doc description to keep same.

On the other hand, for coder, they may like to write the test code as first and write test case in excel at later time.Maybe somebody doesn’t like any doc. So the tool can help them to generate the test cases in excel by automation.

Also the tool can provide the html style test case so that it can be integrated with Jenkins. Having it, you can check the daily run test cases in Jenkins and from the cases description you also can locate the position easier.


1.maven project

How to use it

step 1: configure pom.xml

add followed two configure parts:dependency and plugin into pom.xml: note: the dependency’s last version can check the maven central:

ALERT pls use the latest version.


step 2: use @TestCase in your code


                        module="module one",
                        id =1,
                        title ="case title 1",
                        steps ={
                                "case step one",
                                "case step two"
                        results ={
                                "case result one",
                                "case result two"


step 3: generate excel and html(with excel content)

execute: mvn apt:process or apt:test-process

the goals can refer to :

output excel’s dir: it is decided to outputDirectory configure by default:

  • for apt:process, the output dir is targetgenerated-resourcesapt
  • for apt:test-process, the output dir is targetgenerated-test-sourcesapt

More use examples

Use 1: How to generate office 03xls excel file instead of 07xlsx’s?

add option: excelType=xls


Use 2: How to change the excel’s name instead of TestCase_Date.xlsx?

the excel file’s name is TestCase_Date.xlsx format. if you want to change it, you can:

add option: excelType=xls


Use 3: How to change the excel’s output dir instead of using outputdirectory ?

add configure: outputdirectory:


Use 4: How to bind to other maven lifecycle phrase?

if want to bind to test,add the executions to maven apt plugin:


and run mvn test can trigger both process and test-process for maven apt

Use 5: How to integrated with Jenkins?

1. set the output file to fixed name: can refer to <use 2> add set the option forceCreateFile to create file no matter is there any cases created so that the html publish plugin not to report build fail when no cases existed.


whole configure:


2. configure the jenkins’ job with html publish plugin

the result is similar with:


Problem 1: java.lang.NoClassDefFoundError: org/apache/poi/ss/formula/udf/IndexedUDFFinder

the root cause is that:

the tool use 3.10’s poi dependency version, but if your pom.xml had existed lower verison for it which not supported IndexedUDFFinder, it will popup the error.

the solution is to remove the dependency for the lower’s version’s. for jar dependency can use exclude configure such as followed configure:


Problem 2: how to format the annotation to good style

change the eclipse’s formmater:

->windows->preferences->java->code style->formmater ->Line Wrapping

Problem 3: jenkins: html publish plugin report build fail when no any cases existed

set the option to force creating file so that it can avoid copy fail.


Problem 4: error: annotations are not supported in -source 1.3

the jdk1.3 not support annotations. so you can change maven compile plugin’s compile level to 1.6.


Problem 5: can’t show Chinese rightly in excel

should config encoding method.



傅, 健

程序员,Java、C++、开源爱好者. About me