File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Junit testcase doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Junit testcase doubt" Watch "Junit testcase doubt" New topic

Junit testcase doubt

vasanth raman

Joined: Aug 13, 2009
Posts: 24
how to write a test case for this method
public class Firstjava {
public void multiply(int x, int y) {

David Newton

Joined: Sep 29, 2008
Posts: 12617

Why would you want to unit test the JDK?

And what a terrible method name.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I don't really see how he is testing the JDK but I totally agree with your comment about the method name.

If you want to test standard output you can set a different PrintStream with System.setOut() in your setup method and remove it in your after method. Then in the test methods you can compare the expected output with the toString of the PrintStream.

// Edit: I don't think that all PrintStreams will work but ByteArrayOutputStream will work.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
I agree. Here's the link:
subject: Junit testcase doubt
It's not a secret anymore!