# The Testing Pyramid in Practice for Django with Monica Oyugi

Source: https://djangotv.com/videos/djangocon-us/2026/the-testing-pyramid-in-practice-for-django-with-monica-oyugi/
Date: 2026-10-26
Speakers: Monica Oyugi, Speaker 2, Speaker 3
Text: lightly edited for readability (verbatim on the page)

## Transcript

**Monica Oyugi:** [00:14] It's a pleasure to be here today, and I feel honored to be speaking for the first time at DjangoCon US. I've been an organizer for three years. I do lots of testing, so I have a very funny story, and I don't know why my career keeps on changing. I started off as a WordPress developer, moved to a software engineer for two years. I'm sorry, I got bored because I was tired of the bugs, and then I found QA. It's been working for me for the last five years, and I hope I don't change that. Today we're going to talk about the testing pyramid in practice that I use and the ones that most of you use for your Django applications. My name is Monica Oyugi. I'm from Nairobi, Kenya, and

[01:00] It took me like 26 hours to get here, but I'm used to it anyways. I do a couple of community-organizing roles, like for DjangoCon US, this conference. I'm part of the code of conduct for PSF and also a Py festival back home, and also PyCon Kenya. It's happening in October. If you want to come to Kenya, this is a chance for you to come and visit. We have lots of things to do over there. I also try to speak at conferences to make sure that I get to give people what I do. When it comes to testing, apparently nobody sets you out on how to do it, because we're used to writing code and not everybody has the time to test.

[01:46] Because as long as it works, we can go ahead and deploy. But nowadays we have software engineers and software testers who are there to help us test our code. I'm sure probably most of you have come across this 15-minute moment where you run a code and it runs, and you're like, “Oh, I'm having a good day.” And it's just one file that you haven't tested, and later on you realize that you had to go back and test it. So we have a rhythm that we follow for the process of testing, where you report a bug, you patch it, and then you can add something into it, either to do regression testing, ship it, and repeat in that loop to make sure that your testing process works. But we're going to look at these shapes of the code.

[02:34] So where does this pyramid come from? I've been reading a book by Mike Cohn. It's called The Succeeding Process of Agile Testing, and it's very interesting. He wrote the book in 2009, and a whole part of the book has this pyramid schema, where he enables people to use it to do well testing, mostly in the agile testing group. This is a picture of how I could tell it—not a pyramid per se, but this is how I do my testing as a person. So we have different types of testing. We have the manual and the automation bit. The manual bit is the people who do end-to-end testing, mostly.

[03:20] And we have several categories where we have white box, black box, and gray box testing. Also, when it comes to black box, it's been categorized into two: functional and non-functional. Today we're going to look into unit, integration, and system integration. So it's unit testing, integration, and system. These are part of the three pyramids that Mike talked about in his book. We also have non-functional testing, where we have performance, usability testing, and compatibility. We're going to just briefly look at that. From this pyramid, you'll see it starts with unit, integration, and E2E. Unit testing, most of it, is part of the pure functions and models.

[04:06] So if you have the MVP and you need to do all the process of testing the models, views, templates, or anything, we use the unit test. These are majorly done by, I could call them, engineers, because sometimes you write unit tests and you use your tests to run through the whole code. We also have integration testing, where it involves testing the database, APIs, and any other system that was integrated with your application. Then we also have end-to-end tests. These are mostly the user manual tests, where you do the end-to-end from login up to the process of payment. For example, if you're trying to test a shop application where people buy products and stuff.

[04:53] And there's a funny story about Google. In February 2011, I think it was on a Sunday. I was still in high school. I didn't manage to experience this, but I read somewhere. In February 2011, Google had this upgrade where they were doing the storage upgrade, and it happened that it cleared all the inboxes. So people woke up on Sunday morning, American time. It was like another time in other countries. They woke up in the morning and found the inbox was empty. It happened as a process of somebody trying to do an upgrade, and I think proper testing wasn't done, according to that article. So what they did, they just did a rollback, like Control-Z, and then they were able to recover everything. And, yeah, we should normalize

[05:38] doing rollbacks in case you have a change and somebody's doing regression testing to see if the feature that you built might have affected the whole or entire application that you're building. For that layer, unit test is one of the easiest that people prefer because it takes a little time. There's no database involved, no client; it's just you. And there are several tools that we use for this. I try to use Selenium because it mimics the way a human would basically test this application. You just give it commands, and then it opens your Chrome browser and runs through it. Playwright also does the same. For integration, it takes some milliseconds as well, but it's special, but it could take a longer time because it involves

[06:29] you testing the DB, and some of these ORM tests also involve writing test cases, because these test cases would act as a guide for you to do the E2E tests. E2E tests are the hardest, in my opinion, and they take a lot of time because you have to go through each module, each layer, everything, from login, the whole dashboard, and everything. So there's an ice cream pattern that Django apps apparently have grown into in the suite. And according to this, the CI runs for about the length of a coffee break, which everyone is afraid to touch on the test.

[07:16] But we can also normalize using it. And there's the app pattern hourglass, which is like part of the unit tests and end-to-end tests, which handles almost everything and checks everything when it comes to views, serializers, and the ORM process in between, all through this testing. So let's map into Django itself with the three pyramids. Unit testing involves all this process of doing the technical setup, including running migrations into it. Integration could involve things to do with middleware, permissions, and signals, as the way I've highlighted them over there. And then E2E handles all the flows from the human perspective, where they go through it.

[08:03] It doesn't involve any code testing, but basically most of the time you'll find that humans are involved during this process. On the first layer, there's no database, there's no client, and there's a network that is A to E. This is a sample of the unit test in practice, where you find that you just define what you want and then indicate the price. For example, if you wanted to test something that costs that amount, then you just apply the discount price and equal it to the decimal number that you want. When you run it, it will just give you the correct results. For the sample tests and test cases, you'll find that for the simple test cases, there's no database involved, and it's tend

[08:53] to be faster, which queries everything the way it should be. And when it comes to the test cases, it wraps each test in a transaction role where you have to describe the test case scenario, the test data. There's a process of how the test cases are written. It could be the test ID, test case scenario, the test data, expected results, and everything that you need. This is one of the best documents that could help you easily navigate the test cases. For the Django test runner, there are a couple of commands that we could imply and use, which I've listed there. Some of them include duration, which could help you print the slowest test run. You could assert the query

[09:38] to set it equal, which could help rename the query in the right proper way. We have the async client. I think the previous speakers talked more about it. If you're kidding. And without this, wrapping every test on our own called event loop, all this scaffolding. And then we also have parallel, which is more about isolation and debugging, and has enabled us to improve how we do our Django testing apps. I use PyTest a lot, and I think, in my opinion, PyTest is one of the best tools when you want to test Django and Python applications because it's easier. When you set up an environment with NCP in your

[10:26] favorite IDE, you set up an environment, and then you can just insert URLs depending on the projects, and it runs smoothly. You can find me in the hallway, and then I can explain this more. So the second part is the integration tests, which involves all these integration parts with DB and APIs. This is a sample of the code that you can use to run all the integration tests, and also to help skip features. I found this interesting line where you can have a 200-line JSON of features, and this code can easily try to export it.

[11:12] and help you to test the initials and also set fields in a manner that it's easy to arrange them in a way that's easy to handle and test properly. When you come to the mock edges of your system, mocking for me involves the process of mimicking results. I was working in a finance fintech where we were integrating our systems with DT1, and we'd integrated our flow. DT1 provides the funding for the project that you're doing. So, there, when we were doing the testing, the APIs weren't working, and we had to do the whole mocking process. So we had set up a whole mock

[11:57] test where we make sure we have the APIs running, and then we look at Postman and see the results and mock it through. So this type of integration really helps you to have real scenarios on how the database works, Postman, and any other tool that has been integrated with the system. On top of the pyramid, we also have end-to-end tests. As I mentioned earlier, you can use Selenium, Playwright, and if you love working with JavaScript, you can also use Cypress. This is a sample of the code that you can use when you want to run E2E tests. So every layer has got its own goals. Depending on what you want, you can always try to achieve it.

[12:43] I think I've talked about all these, some of the basic commands that could help you just run the tests. Before we add something, you have to make sure and ask yourself so many questions. Depending on what you're testing, whether it's integration, E2E, or unit test, when you look at E2E, does this actually need a database? If you feel like it doesn't need a database, then you select which type of testing you want to carry out. If it needs a whole request-response cycle, you know, this could be an integration test. And if you genuinely need a browser to be involved, or you're testing the code, this could be unit tests. So that's it. And if you

[13:29] you are a QA engineer, I would love to know how you do your testing, what pyramid you use, and we can collaborate on more.

**Speaker 2:** [13:44] Monica will be taking questions, so any question

**Speaker 3:** [13:51] As regards the database, do you think you need to have a separate test database? And how live should the data in there be?

**Monica Oyugi:** [14:04] I think you'll have a different test on database according to how we do it, because sometimes you can test the database. For example, if you have queried your database with Postgres, you can test it separately. And then you can also do another whole of testing using the application that you've used to integrate with the database. Yeah, unless you have another preference, but that is how I do it, and it works. But it's important to test the database separately.

**Speaker 2:** [14:35] Okay, that'll be all right. Thank you so much, Monica.
