Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you test the integrity of a properties file

 
Junilu Lacar
Bartender
Posts: 7480
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been using a JUnit test case. The problem is that it's pretty tedious: every time I add a new key, I have to change the test case. This has made my team lead think that there's little value in following this approach, even if a recent bug we encountered could have been detected much faster had the test been updated to include the key that had been mangled by a global search and replace. I kind of see his point though.
How would you test that a properties file contains all the keys that your program expects?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still not a really big fan of using a properties file in my testing. I always feel like I'm maintaining something twice.
Perhaps such unsophisticated comment solicitation wasn't your intent.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have any suggestions yet, just a bunch of (hopefully thought-provoking) question...
Originally posted by Junilu Lacar:
I have been using a JUnit test case. The problem is that it's pretty tedious: every time I add a new key, I have to change the test case.

What's so tedious about adding a property key to the testcase?
Isn't it true for *every* change to the system that you need to adjust the tests?

How would you test that a properties file contains all the keys that your program expects?

What does happen if a property is absent? Why don't your other tests find that malfunction?
Will the file get changed after the system is deployed (by the customer/user, for example)?
 
Junilu Lacar
Bartender
Posts: 7480
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dirk: I'm working on a Struts application and the properties file is the ApplicationResources.properties. And yes, the team lead's objection did come from the same feeling of having to maintain something twice.
Ilja: Your questions are actually very useful. If I can't find an alternative to the test case, at least I'll have some arguments for using it.
A number of things can happen when a properties key goes missing, depending on how the code was written. Unfortunately, our team isn't officially using the TDD approach (although I often hear the team lead saying he wants to use JUnit) and I came up with this test case as a front-line defense. Since I have it though, I don't think my other test cases really have anything specific in them that would help detect a problem in the properties file.
The test case has worked well for me and the code I have worked on but other team members seem pretty blas´┐Ż about writing test cases. So, I am just trying the "Stone Soup" approach and I'm keeping my hopes up that the other JUnit tests that I have will prove themselves valuable later. What I did with the properties test case didn't seem to pique any interest though and that was a bit discouraging so I was just wondering if there was any other approach.
 
The Moose
Bartender
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could hire a Moose or two to assist in your testing. That would get their interest up!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic