This post originated from an RSS feed registered with Java Buzz
by Erik C. Thauvin.
Original Post: Testing Private Methods
Feed Title: Erik's Weblog
Feed URL: http://erik.thauvin.net/blog/feed.jsp?cat=Java
Feed Description: The Truth is Out There!
I've been playing with TestNG for a few days now. I really like it. It makes me want to write more tests.
I was wondering if there was a way to create a test for a private method, so I went to the source. I asked Cédric about it. He mentioned that I should use the Reflection API.
The goal was to write a test for the validate method in the following class:
package net.thauvin.erik;
public class Example {
// ...
private static int validate(String username, String password, int days) {
// ...
return days;
}
}
In order to invoke the validate method in my test, I simply needed to: