my dog learned polymorphism
The moose likes Testing and the fly likes Better way to test Message Digested String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Better way to test Message Digested String" Watch "Better way to test Message Digested String" New topic

Better way to test Message Digested String

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 547

Hi All,

We have a utility class, for which I'm trying to determine some meaningful test cases. This utility class is basically used to encode the given string value.

In brief,

A method in our utility class, uses a Message Digest using the algorithm "SHA-512", performs the digest on the byte array of the input String and then encodes the byte array using org.apache.commons.codec.binary.Hex and the resultant char[] array is converted back to String and returned.

For my tests, what I'm doing is as follows

Apart from this, I could not find any meaningful testcase. To be frank, I'm not even happy with this test case. I'm looking for more intelligent test case, where I wish to decode the encoded string and compare with the resultant with the original string. But I know that, we can not determine the value, given a hash, though I can decode the char array using Hex. So what can be done to make the tests robust.


Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33119

What are you trying to test further? Presumably the Apache library is already tested. All you are doing is changing the format yourself. One test case I can think of is to check the encoding doesn't change - store the result of SHAS2.encode(str1) in a constant as the "golden master".

As an aside:

is better than

The former gives a clearer error message about what is different. With encoding this isn't a big deal. With other values, it is very helpful.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 547

I agree with you.

I agree. Here's the link:
subject: Better way to test Message Digested String
It's not a secret anymore!