aspose file tools*
The moose likes Testing and the fly likes Giving more expressive name to test cases in surefire test execution report Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Giving more expressive name to test cases in surefire test execution report" Watch "Giving more expressive name to test cases in surefire test execution report" New topic
Author

Giving more expressive name to test cases in surefire test execution report

jyoti vermakat
Greenhorn

Joined: Oct 04, 2013
Posts: 8
Hey,

My application has few junit test cases, which performs testing of reports. Each test case correspond to one report. These test cases are executed via maven in Jenkins and test execution report is presented to team (including BA) from Jenkins.

As the test case name follows the camel case structure, the test execution report displays the test name in camel case. Now the requirement is to display the test execution result report in such a way as it displays ReportName in place of test case name in test case execution report. This will give report name vise view of correctness of report.

Considering that the report names might have space or special characters as well in it. Can someone please suggest how to achieve it ?




Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hey Jyoti,

I have a solution, which would fulfill your need partially. The solution goes as following -
1- Make your Junit test case with Junit 4.0, this will help you in eliminating test prefix from all of your junit test cases
2- Name all your test cases as the report name (by eliminating the special characters)

After this, test case execution report would have almost report name instead of unsimilar test case name.


Regards
Salil Verma
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

I picked up author Neal Ford's convention for naming tests. Neal eschews camel case for test case names and uses mostly lower case and underscores instead reasoning that with tests, readability is more important than following standard naming convention. When using JUnit 4 and the @Test annotation, this becomes even better because your test names no longer need to start with "test".

The result, IMO, is a more readable list of test names. Here's a sample list of test names for a hypothetical class:

Notice that you can get a pretty good idea of the kind of functionality being tested just by looking at the names of the tests. We end up with some pretty long test names but the fact that the list of tests also gives you a very nice summary of the design of the class under test, we don't mind the long names and the different naming convention. Notice also that when a test exercises a specific method, the test name starts with the method name using normal camel caps convention.


Junilu - [How to Ask Questions] [How to Answer Questions]
jyoti vermakat
Greenhorn

Joined: Oct 04, 2013
Posts: 8
Hey Salil & Junilu,

Thanks for your responses.

Your suggestions will definitely improve readibility of purpose of test cases more than it is currently.
Can you please suggest if there is any way we could tweak the test cases to display names with spaces and special characters as well at the execution result. This name not necessarely need to be the name of test cases, as test case method name does not support special characters or space in it. Any way probably with annotaions or something..


Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

jyoti vermakat wrote:
Can you please suggest if there is any way we could tweak the test cases to display names with spaces and special characters as well at the execution result. This name not necessarely need to be the name of test cases, as test case method name does not support special characters or space in it. Any way probably with annotaions or something..


Sometimes you just have to put your foot down and say "No"
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30548
    
152

I agree with Junilu. This isn't the purpose of test names. If you absolutely need to do this, I'd suggest running the reports through a post processor script you write. That way the test names can be code and the "report to whomever" has spaces.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
jyoti vermakat
Greenhorn

Joined: Oct 04, 2013
Posts: 8
Hey Jeanne,
Thanks for your response.

I'd suggest running the reports through a post processor script your write


Can you plese give me an example (pobably a link) about the way to run report through post processor to name the test case in result as we want ?

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30548
    
152

I don't have an example because I have never done such a thing. (And would tell anyone who asked me to why I think it is a bad idea.)

However, it is just a search and replace (on multiple files.) You could write a Java program to do this. Or any other language. This is also an opportunity to revisit the "requirement." Is it really worth to whomever is asking you to do this that you spend a day or more writing this program instead of doing actual productive work?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Giving more expressive name to test cases in surefire test execution report