What is testing? As I said, testing does not mean that we test our application manually,
we obviously do that and we should do that. With testing here,
I mean that we write automated tests.
So what we typically do is we build an application,
then of course we test it manually in the browser and then we ship it to a server,
now there's one extra step we can add in any development workflow and that is that we don't just ship
the app after testing it manually but that we also have automated tests.
Now these are tests which run automatically, we write them and then each test tests a tiny fraction of
our application,
that's a so-called unit test,
it tests a unit of our app.
The idea behind such tests is that since we define these tests,
if we change anything in our application and that breaks our app or breaks a component in our app then
the respective test will fail and hence we might get a warning about a potential error we introduced
before we even have to find it by manually testing the browser. In more complex applications,
this is especially important since there, it's way easier to break something without quickly noticing
it. There also is a different way of thinking about testing,
instead of adding it in the end of the build workflow, there also is this idea of test driven development
which you might have heard about, test driven development imports the tests first, there you write the
tests before you write any application code
and therefore all the tests will of course fail initially but then you add the application code and
the test should pass step by step.
That's not the concept
I will show you here,
this is no complete testing course, not at all
instead I want to show you how to write these unit tests and you can of course then build up on this
knowledge to use it in whichever way you want to use it.
This however is the core idea of what testing is and why would we test?
Well that is exactly what I already mentioned,
we might have an application and there, we might have a component which does a couple of things as suggested
here on the left and in the first draft we created for the component,
it may pay us all the tests we defined for this given component
so we wrote test for a given component and they pass.
Now when we change something in this application or we add a new feature and that affects this component
and we change something in that component for that reason then we still might have some passing tests
but maybe some of our tests then fail
and that's exactly showing us then where we need to look into our code and potentially fix or adjust it
or fix or adjust our test to the changed requirements, either of the two,
but at least we have to take a look at that
so that's the idea behind testing. Now to be able to test,
we need some testing tools.
Let's take a closer look at these in the next lecture.