[No Audio]
One last point to bear in mind, if I just set a
breakpoint here and then debug test again
when it's running the first test method, you can see
here we have this calculator @816, which is the
reference to the instance
[No Audio]
we just put a breakpoint here and here.
[No Audio]
So if I just play now, then we'll see the
test add positive numbers is going to be executing
against instance 816, we can see here.
So I'll just play that. That's fine.
And on the second test being executed, we can
see now that calc is now a different instance.
It's a different object Calculator@828, which
means that when I end up in the second
method testAddZeroToPositive, this test method
is running against a different instance.
Let's play that off.
So it completes.
So this is a good thing to point out is,
the fact that the test fixture which you have and
which you set up in the method which is annotated
with @Before that's, set up fresh each time.
Not only is the setup method called fresh
each time, which creates a new instance of
whatever objects your test fixture is composed of.
Not only that, but also the test itself.
The test class itself, is also recreated each time.
And in addition to @Before, there's also @After, which
is almost never used in JUnit, at least in unit tests.
But that would enable you to tear down any
state from the fixture which you wanted to do.
But as I said, for unit tests in
general, these are in memory, so we don't
tend to use teardown methods for those.
And finally, if you needed to do any setup
which applies to all of the test methods.
So you're really talking about doing
test setup at a class level.
Then there's also the @Before
class annotation you can use.
And again, there's a corresponding @After
class annotation as well, which is the
opposite from a tear down perspective.
Anyway, that should give you some nice insight on
how to use JUnit as a test framework.
And now we're in a great position, where we can start
to actually be prepared to use it to write our unit
tests, which in turn use the Mokita Mocking library.
And we'll see how to do this
as we progress through the course.