Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Junit: overriding original class private methods

Reply
Thread Tools

Junit: overriding original class private methods

 
 
Robert M. Gary
Guest
Posts: n/a
 
      12-29-2006
I have a class that when run will call a private sendEfvent() method
that sends data to an external process. I would like to override that
behavior in testing and just report what is set to avoid the
complications, etc of having to use external processes during unit
testing.

I don't think I can just use an assertTrue() because I also want to
know how many times this private method is called (i.e. is it sending
the correct number of copies out)?

Is there a way I can cause Junit to stop the JRE from calling the true
sendEvent() method and instead call something in my test class??

-Robert

 
Reply With Quote
 
 
 
 
Jim Korman
Guest
Posts: n/a
 
      12-29-2006
On 28 Dec 2006 17:23:22 -0800, "Robert M. Gary" <(E-Mail Removed)>
wrote:

>I have a class that when run will call a private sendEfvent() method
>that sends data to an external process. I would like to override that
>behavior in testing and just report what is set to avoid the
>complications, etc of having to use external processes during unit
>testing.
>
>I don't think I can just use an assertTrue() because I also want to
>know how many times this private method is called (i.e. is it sending
>the correct number of copies out)?
>
>Is there a way I can cause Junit to stop the JRE from calling the true
>sendEvent() method and instead call something in my test class??
>
>-Robert


Consider using an Interface that exposes the send event behavior.
Then your sendEfvent() method calls this strategy's send method.

During testing you can set the strategy to a mock implementation that
counts data, or better yet, exposes the message so that you can then
unit test the message contents.

Jim
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Overriding private methods snacktime Ruby 1 10-26-2007 09:38 PM
Why is define_method private? Plus,what's the point of private methods? Daniel Finnie Ruby 3 12-16-2006 10:09 PM
Public Data in Private Class or Private Data in Public Class? DaveLessnau C++ 3 05-16-2005 06:53 PM
Can private methods be overriding? Hongzheng Wang C++ 5 12-05-2003 01:24 AM



Advertisments