Junit: overriding original class private methods

Discussion in 'Java' started by Robert M. Gary, Dec 29, 2006.

  1. 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
     
    Robert M. Gary, Dec 29, 2006
    #1
    1. Advertising

  2. Robert M. Gary

    Jim Korman Guest

    On 28 Dec 2006 17:23:22 -0800, "Robert M. Gary" <>
    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
     
    Jim Korman, Dec 29, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hongzheng Wang

    Can private methods be overriding?

    Hongzheng Wang, Dec 4, 2003, in forum: C++
    Replies:
    5
    Views:
    4,335
    Hongzheng Wang
    Dec 5, 2003
  2. DaveLessnau
    Replies:
    3
    Views:
    447
    Howard
    May 16, 2005
  3. Daniel Finnie
    Replies:
    3
    Views:
    209
    Logan Capaldo
    Dec 16, 2006
  4. snacktime

    Overriding private methods

    snacktime, Oct 26, 2007, in forum: Ruby
    Replies:
    1
    Views:
    95
    Evan Moseman
    Oct 26, 2007
  5. Kenneth McDonald
    Replies:
    5
    Views:
    372
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page