The Testing Pyramid in Practice for Django with Monica Oyugi

This video features Monica Oyugi at DjangoCon US 2026 in Chicago, Illinois, USA.

The Testing Pyramid in Practice for Django with Monica Oyugi
0:14:49
Published October 26, 2026
54 views

Many Django developers write tests reactively β€” covering whatever feels important in the moment and end up with suites that are slow, hard to maintain, and unevenly distributed. This talk addresses that by introducing the testing pyramid as a deliberate, structured approach, anchored in Django's latest testing capabilities.

This talk was presented by Monica Oyugi at DjangoCon US 2026 in Chicago, Illinois, USA
https://2026.djangocon.us/talks/the-testing-pyramid-in-practice-for-django/

LINKS:
Follow Monica Oyugi πŸ‘‡
On Mastodon: https://mastodon.social/@monics
Website: https://medium.com/@monicaoyugi

Transcript

2,330 words · auto-generated · en Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:14

Speaker 1: It's a pleasure to be here today and I feel honored to be speaking for the first time at Django Kong US Being an organizer for three years. Yeah. And I do lots of testing. So I have a very funny story and I don't know why my career keeps on changing. So 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 Yeah. So today we're gonna talk about the testing pyramid and practice that I use and the ones that most of you use for your Django applications. So my name is Monica Oyugi. I'm from Kenya, Nairobi, and

1:00

Speaker 1: took me like twenty-six hours to get here. But I'm used to it anyways. So I do a couple of community organizers uh like for DjangoCon US, this conference. I'm part of the code of conduct for PSF and also a PI festival back home and also PyCon Kedja, yeah, and it's happening in October If you wanna come to Kenya, this is a chance for you to come and visit. We have lots of things to do over there. And then also I try to speak in conferences to make sure that I get to give people what I do So 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

1:46

Speaker 1: because as long as it works, we can go ahead and deploy. But um nowadays we have software engineer software testers who are like there to help us test off code. And I'm sure probably most of you have come across this 15 minute of you run a code and it runs them like, oh I'm having a good day. And it's just one file that you haven't like tested and later on you realize that you had to go back and test it. So we have A rhythm where 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 a regression testing, ship it, repeat in that loop. to make sure that your testing process works, but you're gonna look at these shapes of the code.

2:34

Speaker 1: So where does this pyramid come from? I've been reading a book by Mike Conn. It's called The Succeeding Process of Agile Testing, and it's very interesting. So he did he he wrote the book in two thousand and nine and he has a whole part of the book has a whole this pyramid schema where he he enables people to use it to do well testing, mostly if in the agile testing um group. So 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 are the people who do like end-to-end

3:20

Speaker 1: mostly. And we have several categories where we have the white box, black box. greatest thing. And also when it comes to black box, it's been categorized into two. We have the functional, non-functional. And today we're gonna look into the unit integration and system integration. So it's The unit testing, integration, and system. These are part of the three pyramids that Mike talked about in his book. We also have the non-functional testing where we have the performance, usability testing, and compatibility We're going to just briefly look about that. So from this pyramid, you'll see it starts with the unit integration in E2E. And unit testing most of it is part of the pure functions models.

4:06

Speaker 1: So if you have The MVP and you need to do all the process of which test the models, views, templates, or anything We use the unit test. And these are majorly done with um 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 using if you are trying to test a show publication where people buy products and stuff.

4:53

Speaker 1: 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 it read somewhere. Yeah. So in 2011, February, Google had got this upgrade where they were doing the storage upgrade. And it happened that it cleared all the inbox. So people wake up on Sunday morning American time. So it was like another time in other countries. So they woke up in the morning and found the inbox that was empty. And it happened as a process of somebody was 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 like recover everything. And yeah, we should normalize

5:38

Speaker 1: doing um rollbacks in case you have a change and somebody's doing regression testing to see if the feature that you build might have affected the whole or entire application that you're building. And for that layer Uh 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 it is And there are several tools that we use for this. Like I try to use Selenium because you m 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. And prerite also does the same. For integration, it takes some of the milliseconds as well, but it's special, but it could take a longer time because it involves

6:29

Speaker 1: You testing the DB and some of these ORM also involves for you writing test cases, because these test cases would act as a guidance for you to do The E to E tests and 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, each everything so from login um the whole dashboard and everything so there's an ice cream pattern that Django apps apparently have grown into the suit. And according to these, it's that the CI runs like a coffee break length, which everyone is afraid to touch on the test.

7:16

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

8:03

Speaker 1: Doesn't involve any Any code testing, but basically most of the time you'll find that humans are involved during this process. And on the first layer There's no database, there's no client, and there's a network that is A to E. And this is a sample of the unit test in practice where you find that you just uh define what you want and then you 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 um the decimal number that you want. And then when you run it, it will just give you the correct results. So for the sample tests And test cases. You'll find that for the simple test cases, there's no database that involves around it, and it's tend

8:53

Speaker 1: to be faster, which um queries everything The way it should be. And when it comes to the test cases, it shrubs each test in a transaction role where you have to describe the test case scenario, uh, the test data There's a process of how the test cases are written. So it could be the test ID, test case scenario, the test data, expected results, and everything that you need. And this is one of the best documents that could help you to easily navigate the test cases So for the Django test runner, the couple of commands that we could imply and use, which I've listed there. Some of them that could be duration, which could help the Help you to print it, to print the slowest test run. You could assert the query uh

9:38

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

10:26

Speaker 1: favorite um IDE. So we set up an environment and then you can just insert URLs depending on the projects and it runs smoothly. You can find me on the Halloween then I can explain this more. So the second part for 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 to skip features, I found this interesting line where you can have a 200-line JSON features and then which can easily this code can easily try to export it.

11:12

Speaker 1: and help you to test the initials and also set fields in a matter that it's like arrang them in a way that it's easily to handle and test it properly. When you come to the mock of edges of your system, mocking for me involves the process of mimicking, like results I was working in a Now finance fintech where we integr we're integrating our systems with DT1 and we've integrated our flow. So DT1 provides the funding for the project that you're doing. So the applic there when we were doing the testing The APIs aren't working and we had to like do the whole mocking process. So we had set up a whole mock

11:57

Speaker 1: tests where we just inject we have We make sure we have um the APIs running and then we look at the postman and see at 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. So 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 use working with JavaScript, you can also use Cypress And 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 with what you want, you can always try to achieve it.

12:43

Speaker 1: I think I've talked about all these, some of the basic commands that could help you to just run the tests. And before we add something, uh you have to make sure and ask yourself so many questions. Does So depending with what you're testing, when it comes to integration, E2E or unit test, so 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 that you want to carry. If it needs a whole request response cycle, just you know this could be an integration test. And if you need a browser genuinely need to be involved, or testing the code, this could be unit tests. So that's it. And if you

13:29

Speaker 1: if you are a QA engineer, I would love to know how you do your testing, what pyramid do you use, and we can collaborate on more.

13:44

Speaker 2: Um Monica will be taking questions, so any question

13:51

Speaker 3: Uh as regards database, do you think you need to have a separate test database? And how live should the data in there be?

14:04

Speaker 1: I think you'll have a different test on database according to how we do it because sometimes you can 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.

14:35

Speaker 2: Okay, that'll be all right. Thank you so much, Monica. Thank you.

Presenters

Conference

DjangoCon US

August 24 - 28, 2026

Chicago, Illinois, USA

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos by Monica Oyugi

More videos from DjangoCon US