[No Audio]
In this video, we're going to write some very
basic production code that we can write a unit
test for and start coding the unit test itself
by introducing you to the @Test annotation.
Let's jump in.
So let's go back into CalculatorTest.
So currently now if I right click this, if
I go up here and right click, then you'll
see I can't do anything with it.
There's no run,
menu which I can use which will
enable me to run it as a unit test.
So to fix that, what I need to do
is to put in a test method, public void
this doesn't return anything testAdd.
It's not going to take anything either,
so that's going to be empty.
[No Audio]
Now, there are different ways of being able to name
your test methods and we'll cover that in a later unit.
But for now we're just going with
an arbitrary convention of taking the method
we're testing the method name there, which is add
because we have in here a Calculator add method.
You can see,
[No Audio]
I'm just prefixing it with the word test.
So to make it a test, JUnit gives us these
annotations which we can use as part of its API.
And one of the annotations, probably the
most important annotation is the
org.junit test annotation.
So if I just do @Test here from
org.junit and hit enter, you can see we've
imported it there, which means that now if I
right click,
[No Audio]
you can see we have this new
option here which is Run 'CalculatorTest'
has now recognized that test case, due to the
fact that we put the @Test annotation on it.
So now we have a test to run
and some production code we can actually test.
Let's see how we can do that in the next video.