I started off with creating a new library directory and like all of my other examples, let's keep this
simple and just see the important aspects of what we are working on.
So let's start off with the default example that Rust gives us and let's break it down really quickly.
So at the very top, we see we have cfg test C CFG stands for configuration and tells us to only include
the following when given a certain configuration option.
So we are essentially configuring the following only for when we want to run test.
Then we create a test module and we add this bit.
Right here.
And what this is going to do is it's basically going to tell the rest compiler, hey, the following
function is a test and I'll show what happens when we forget that little bit right there.
And then inside of that, we have the the test function and we have many options that we can choose
from and we can see in the default example, it has the assert equals macro.
And this is going to make sure that the left hand side is going to equal the right hand side.
So to run this, we simply run cargo test and we concede that it outputs running one test and it is
testing.
It works, which is the name of our function.
And in this case it passed.
So it outputs okay to us.
And it lets us know that we had one that passed.
So what happens if we take this little porch portion out that I mentioned earlier and now we try to
run it?
Well, it says it's running zero test.
Right.
So now the rest compiler doesn't know that this is.
So that's why that little bit is important to include above the function.
So we can see that everything worked.
So let's add another function and make it a failing one just to see what that looks like.
And we can do this by using the panic keyword.
So remember, we've got to include test and then we're going to say function.
It fails.
And now we're going to just say.
Panic
test failed.
And now if we run this running cargo test.
We now see what a failing test looks like.
So again, it's going to tell us what function was ran.
In this case.
It fails and it failed, which is great because that's what we wanted to see.
We just wanted to see what a failing test looks like.
And we can use panic to induce a failing test in this situation.
So that's just a very broad overview of testing.
So let's get into a little bit more examples using annotations in the next lecture.