I
I
Ilya Balabanov2015-05-31 15:29:30
Java
Ilya Balabanov, 2015-05-31 15:29:30

How to test protected void java function with JUnit?

Dear friends, we need help. There is a simple GUI toy, it remains only to test some functions. One such processWindowEvent. Actually code:

protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if(e.getID() == WindowEvent.WINDOW_CLOSING){
            System.exit(0);
        }
    }

JUnit generated the following code:
@Test
    public void testProcessWindowEvent() {
        System.out.println("processWindowEvent");
        WindowEvent e = null;
        Frame instance = new Frame();
        instance.processWindowEvent(e);
        // TODO review the generated test code and remove the default call to fail.
    }

I can not understand the very essence of testing this function. Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Emin, 2015-05-31
@ilyablbnv

Not sure what exactly you are asking?

  • Why test? It's up to you. Such a simple method may not be tested.
  • How is a protected method tested? Solved by putting the testing class in the same package.
    stackoverflow.com/questions/440786/junit-java-test...

N
nomit, 2015-07-09
@nomit

In general, protected methods do not need to be tested, they are tested in the same way as private methods within the framework of testing public methods that call these methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question