Structuring Test in Django: A developer’s Journey
Hello Guys, I’m Jeffrey a self taught backend developer, with a deep love for programming and computers, I’ve been coding for the past 2 years now, and it’s been an amazing journey, today I’ll be sharing something new I learnt while working on my recent project.
While working on a cash disbursement app I got to the point where it was necessary for me to write some test to ensure all the functionality were working properly, but I soon realized that I was blank not knowing how to structure the tests. I’ve always avoided writing test because I’ve always seen it as tedious and unnecessary.
But the problem was not writing tests but structuring a project in general. I immediately open my browser and searched for articles and websites talking about testing and structuring them, Chatgpt was also very helpful, as a developer understanding how to search for answers is a must have skill, one method that was very helpful was making use of GitHub to find other projects that were already did what you were trying to implement. After much search I found an answer that worked for me.
In Django there are apps, it’s a way to separate each major functionality of your overall project, like having users separate from payment functionality. in each app I created a test folder(also a module) and in each test folder I added individual test for each files in the folder, each file contained functions and Classes performing various tasks from serialization to interacting with the database(checkout Django documentation to learn more).
So basically I implemented separating and grouping method, each app had it test folder and corresponding test files to each file in the app. Making it easy to find and access tests, you begin to see the important of this as the project gets larger.
Get Aghahowa Jeffrey’s stories in your inbox
Join Medium for free to get updates from this writer.
That’s how I went about solving the structure problem, there are many other methods I could have implemented but this method suits my project. It’s way more organized than having a single module in the root directory where all tests would live, that would create a folder filled with too much test files. Separating and grouping files with similar functionality is coding best practice.
In solving this particular problem I had to understand how software projects in general are structured, one of the difference between a senior developer and a junior is in how they structure projects. This is where design patterns would be considered but that’s beyond the scope of this article, and that’s about it for Structuring tests.
Again I’ve gotten the chance to Improve on my backend skill, which makes me a lot more confident about the internship I’m about to embark on at HNG.
Yh, so speaking of my journey, I recently got accepted in to an internship program by HNG as a backend developer. HNG stands out from all the internships out there, it bridges the gap between learning and implementation, forcing interns to work in a fast paced environment, immediately learning and implementing due to it’s strict deadlines and elimination process, YES, you can get eliminated.
For me, I see HNG as an opportunity to challenge myself. How far I will go before breaking the invincible limitations I put before myself. I want to use this opportunity to gain industry experience, to be able to work in the tech industry and with people, I also plan to make connections. In all, the overall goal is to finish the internship, qualifying myself for the job opportunities it brings at the end of the program. Click to learn more about HNG.
With all of that said the major take away from this article includes the need to understand proper project structuring and where each method should be implemented. Also to give you guys updates on what I’ll be busy with for the next 3 month. I’ll be sharing more on this in later articles, so stay tuned.
Until next time guys👋🏾









