Join Simon Allardice for an in-depth discussion in this video What kind of testing is this?, part of Programming Foundations: Test-Driven Development.
- You may right now have the wrong idea about this course, so understand, this is not a course on how to test software in some kind of generic sense, because testing is a vague word in software development. There's lots of different kinds of testing we could do. We need another word alongside it to make it more specific. Some of the better known kinds of software testing would be things like beta testing, providing a finished or nearly finished application to a group of users and seeing what problems they come up with.
There's performance testing, using profiling tools to measure if we're getting acceptable response times. Is this application running as fast as it should be, or at least as fast as it need to be. There's stress testing, one kind of performance testing where we want to know how well the code works under heavy load, so this web application works fine with one person, what about 100 or 1000 or 10,000 at the same time? There's other kinds of testing. We've got integration testing, testing one app integrating with external other systems.
There's acceptance testing, there's regression testing, there's usability testing. Well, this course isn't about any of these. We're talking here only about unit testing, testing we do as programmers, not as end users. We are testing the code itself, not just the results we might get from clicking buttons on a user interface. So this is about us testing the individual units of our code, the smallest logical pieces possible. So we're proving that a single class works the way that class is supposed to.
More than that, we're proving that individual methods work the way they should, that if we pass in these particular values into that particular method, we will get this specific result back, and we go ahead and prove that this is true. But this is not the kind of testing where you act as an end user as a finished application. We might do that, but that would be later, sometimes much later. We don't wait to have a finished application, we are doing this right from the start, we're testing our code as we write it.
We may not have a user interface yet. We may not have written most of our classes yet. We are still testing our code. So this course is about unit testing, but more than that, it's about having automated unit tests. Because if you want to test down to the level of the individual methods in your application, you don't want to have to manually type method calls into a command line window and then check the results in some massive book of tests. We don't want to do any of this manually again and again, that would be completely painful.
So we will automate this. We will write code that tests our application code. So we'll have our application code, and saved right alongside it and considered just as important, our simple, repeatable, testing code. That might sound like a huge amount of additional work, it really isn't. As you'll see, writing tests is done very simply. It requires minimal code, minimal logic to write a test. And we'll have it so that we can easily write these tests, save them, and then run them repeatedly at the press of a button.
We need it to be as easy to run our tests as it is to compile our code or run our application. And as we build the application, we build our unit tests right alongside them, so we can run those tests 10, 20, 100 times a day. Among other benefits, having automated unit tests allows us to easily validate that any change we make in one place, whether that's tomorrow or six months down the line, we can verify it doesn't break something we did earlier, which makes life much easier when building applications, adding features, fixing bugs.
So with test driven development, we're not beta testing, stress testing, acceptance testing, usability testing, we're unit testing. But that's not all we're doing with test driven development. There's one more idea that we're missing, and that's up next.
The course explores the jargon of TDD—test suites, test harness, mock and stub objects, and more—and covers how TDD is used in the most common programming languages and environments. Plus learn to create, run, and manage the tests and move to a test-first mindset.
- What is test-driven development?
- Using unit testing frameworks
- Creating tests
- Using assertions
- Creating multiple test methods
- Naming unit tests and test methods
- Testing return values
- Setting up and tearing down
- Introducing mock objects
- Measuring code coverage