0

I was trying to understand evaluate() method of Statement class say for example as per the code present in Apply '@Rule' after each '@Test' and before each '@After' in JUnit

The evaluate method actually executes both before and after and then moves ahead.

                @Override
            public void evaluate() throws Throwable {
                // TODO Auto-generated method stub
                try{
                System.out.println("I am Rule1");
                arg0.evaluate();
                System.out.println("I am Rule2");

                }

The part of the result of the above code is :

I am Rule1
I am before
I am Test1
I am Rule2

So, after "I am Rule1", how does "I am before" and "I am Test1" get displayed when at evaluate method?

Community
  • 1
  • 1
Mercenary
  • 2,106
  • 6
  • 34
  • 43

1 Answers1

0

From the javadoc of the @Rule annotation:

The Statement passed to the TestRule will run any Before methods, then the Test method, and finally any After methods

I.e., when you call the evalute() method on the Statement, the above happens. The code you surround the evaluate() call with is called before and after, respectively, the Statement-related stuff.

K Erlandsson
  • 13,408
  • 6
  • 51
  • 67