Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jyoti vermakat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Junilu Lacar
Bartender
Pie
Posts: 7778
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jyoti vermakat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7778
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jyoti vermakat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic