Get startedGet started for free

Introduction to testing

1. Introduction to testing

Hello and welcome! I’m Maria, a senior software engineer. In this course, we’ll cover the basics of testing in Java. Testing is an essential part of writing quality code, and engineers must test their own code to ensure reliability.

2. What is testing?

So, what is software testing? Simply put, software testing is the process of evaluating software to determine whether it meets specified requirements and functions correctly. Testing can be manual or automated. Manual testing is about manually checking the code works. This can take a long time and due to human error, bugs will slip through. Automated testing, on the other hand, involves writing software that tests your software. This is much less susceptible to human error. Modern Java can execute hundreds of automated tests in a few seconds.

3. Edge cases

Testing is so essential in engineering that programmers often say "If something is not tested, it's broken." Many teams do not start implementation until they know how to test it. There are some scenarios in which bugs are more likely to happen. A good example of those are the edge cases. An edge case is an input or condition that is at the extreme or boundary of possible inputs. Common edge cases arise when variables are empty or null, when variables are at maximum capacity, or when they are negative.

4. Example of unexpected behavior at an edge case

Here's an example. This method adds two numbers. It should always work, right? But this code can behave unexpectedly! This is because of integer overflow. Remember, integers have fixed size limits in Java. If we add 1 to the maximum value of an integer, it will overflow and loop back to integer minimum value.

5. Recall: Variable sizes - primitives have limited size

Recall Java primitives have limited size. Refer to this table for the exact sizes. Ignoring those limits can cause some very expensive bugs.

6. Example: Ariane 5 launch

An infamous example is the first flight of the Ariane 5 rocket. This rocket spent 8 years in development and cost over 370 million dollars. It exploded shortly after launch due to an untested and unhandled overflow of a short-type variable.

7. Benefits of testing

Insuring against edge case bugs is just one reason testing is so important. Recognizing and testing edge cases shows seniority and experience as it requires extremely good understanding of programming concepts, and of the project requirements. Contrary to popular belief, testing doesn't slow development. Good tests catch bugs early and speed up debugging. As Robert Martin notes in Clean Architecture, testing saves time long-term. Finally, testing automates enforcing complex requirements and minimizes human error.

8. Let's practice!

Let's now practice encountering some common edge cases!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.