System tests

At some point, your classes, business rules, persistence layers, and so on are combined to form, for example, a web application. Let’s think about how a web application traditionally works. Users visit a web page (that is, their browser makes a request to the server, and the server processes the request and returns a response… Continue reading System tests

What to test in a SQL query

SQL is a robust language and contains many different functions we can use. Let’s simplify and look at queries as a composition of predicates. Here are some examples: In these examples, value < 50, i.customer_id = c.id, c.country = ‘NL’, and value > 50 and value < 200 are the predicates that compose the different queries. As a tester, a possible criterion is to exercise the predicates and check whether the SQL… Continue reading What to test in a SQL query

Database and SQL testing

In many of the examples a Data Access Object (DAO) class is responsible for retrieving or persisting information in the database. Whenever these classes appear, we quickly stub or mock them out of our way. However, at some point, you need to test these classes. These DAOs often perform complex SQL queries, and they encapsulate a… Continue reading Database and SQL testing

Testing larger components that go beyond our code base

In the previous example, the large test gives us confidence about the overall behavior of the component, but we could still test each unit individually. In some cases, however, we cannot write tests for units in isolation. Or rather, we can write tests, but doing so would not make sense. Let’s look at examples of… Continue reading Testing larger components that go beyond our code base

Testing larger components

As always, let’s use a concrete example. Suppose we have the following requirement: Given a shopping cart with items, quantities, and respective unit prices, the final price of the cart is calculated as follows: NOTE The business rule related to delivery costs is not realistic. As a developer, when you notice such inconsistencies, you should talk… Continue reading Testing larger components

When to use larger tests

I see two situations where you should use a larger test: The following sections show examples of both cases and will help you generalize them.

Introduction

Most of the code we tested could be tested via unit tests. When that was not possible because, say, the class depended on something else, we used stubs and mocks to replace the dependency, and we still wrote a unit test. As I said when we discussed the testing pyramid. I favor unit tests as… Continue reading Introduction