File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes How do you test the integrity of a properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How do you test the integrity of a properties file" Watch "How do you test the integrity of a properties file" New topic
Author

How do you test the integrity of a properties file

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

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?


Junilu - [How to Ask Questions] [How to Answer Questions]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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)?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

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

Joined: Apr 01, 2003
Posts: 73
You could hire a Moose or two to assist in your testing. That would get their interest up!


Finally! Animal rights in action!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you test the integrity of a properties file