creating code, you typically want to check it earlier than pushing to the event or manufacturing setting. Nonetheless, ready for a deploy with GitHub actions, or CDK stack deploys with CDK, is time-consuming.
Such time-consuming duties kill iteration pace, which is a essential issue if you wish to develop code successfully. It’s because it is advisable take a look at your implementations correctly to make sure they work. Then, after every change, it is advisable take a look at it once more.
With the most recent coding brokers, creating full native testing scripts is tremendous quick, and one thing I do day-after-day as I write code as a knowledge scientist.
On this article, I’ll take you thru why it is advisable create an environment friendly native testing setup by working a Docker picture and sending take a look at occasions. I’ll additionally present how I do it myself, and the way it helps me develop into a extra environment friendly engineer.
I’ll principally be speaking about the way to work with Infrastructure as Code (IaC), as a result of that’s principally what I’m working with on a day-to-day foundation. Nonetheless, the idea of effectively working your code domestically applies to all programming.
Why it is advisable run code domestically
Firstly, I wish to cowl why we have to run code domestically. The straightforward reply is that:
Iteration pace is among the most necessary features for effectively getting working code to manufacturing
The sooner you may iterate in your code, the higher. Once you develop new performance (or repair outdated performance), you wish to shortly take a look at if it really works, after which iteratively repair the code till it really works as supposed.
If you need to wait 5-Quarter-hour on your code to deploy earlier than testing it, you will have a major problem. Each time you’re not in a position to one-shot an issue, you waste 5-Quarter-hour merely ready for the deploy.
As an alternative, you must run your code domestically. For instance, for those who’re working with IaC, comparable to AWS CDK, you may construct and run Docker pictures domestically, primarily replicating the manufacturing setting, however by yourself pc. This manner, the iteration loop is easy, and the time it takes to construct the Docker picture and run the code.
Constructing the Docker picture is often very quick, contemplating Docker caches earlier builds. Thus, most of your time might be spent working the code with take a look at enter and verifying the output is as anticipated.
If you happen to’re engaged on an online software, you must (and doubtless are already), working the applying domestically, earlier than deploying your code. There must be no distinction when working with IaC.
Learn how to develop domestically as if it have been a manufacturing setting
An necessary facet when creating domestically is that you just’re in a position to intently replicate the manufacturing setting. If you happen to’re writing IaC, constructing Docker pictures, and working the Docker picture domestically:
You’re testing with the very same code, with the identical enter paths, and for those who mirror your .env file to the manufacturing .env file, you additionally mirror the entire variables. Thus, working Docker pictures domestically is the best way to go if you are able to do that.
Create native scripts with coding brokers
Earlier than the discharge of coding brokers like Cursor and Claude Code, it was often a tedious activity to arrange code to run the whole lot domestically. You wanted to construct the Docker picture appropriately, set it to run along with your .env file, and so forth. Otherwise you may wish to run your code domestically as a FastAPI server as a substitute, by which case you confronted comparable challenges.
This isn’t a difficulty anymore, nevertheless. To start out working domestically, I often present Cursor the next instruction:
Create a shell script for me to run this code domestically. The shell script
ought to run the docker picture, and have an optionally available --build flag, which builds
the docker picture earlier than working it. The docker picture ought to load setting
variables from the .env file.
This creates an environment friendly shell script you should utilize. I just like the optionally available –— construct tag, as a result of it’s generally time-consuming to construct the Docker picture, and I don’t at all times have to construct it earlier than working.
Additionally, the next components enable me to run the script simply:
- I by no means retailer precise secrets and techniques in .env. I solely retailer secret references, which my code then picks up from AWS Secrets and techniques Supervisor. Thus, I can push my env file with none fear of leaking secrets and techniques. Moreover, this makes it simpler for others to run the scripts as properly when pulling the code from GitHub
- I create one other file with take a look at occasions, the place I can simply ship occasions to the working Docker picture. This manner, I can simply test the enter and output
- I deploy the testing scripts to Git, so everybody else additionally has entry to them. This consists of the env file as talked about, because it doesn’t comprise any secrets and techniques
Now you will have the precise setup it is advisable run and take a look at your code domestically. Each time you make adjustments, you rebuild the Docker picture and ship the take a look at occasions, making certain that the whole lot is working as supposed.
I like to recommend establishing these native testing scripts for all of your repos and pushing them to Git for sharing. Getting access to these scripts will make your whole workforce extra environment friendly as programmers.
Additional tricks to run domestically
I additionally wish to share two extra tricks to be much more environment friendly, given these native testing recordsdata:
- Run and take a look at Docker picture with pre-commit hooks
- Give your coding agent entry to those scripts
Pre-commit hooks
Pre-commit hooks are code that runs earlier than each decide to git. Typical pre-commit hooks embody:
- Run black . for formatting
- Run mypy for sort security
- Run pytest assessments to verify all assessments cross
Having a pre-commit hook ensures you always remember to run any such instructions earlier than pushing your code. That is extremely helpful and an incredible timesaver. It’s onerous for me to rely the variety of occasions I forgot to run black formatting earlier than committing, and the deploy assessments find yourself failing 5 minutes later, costing me a number of time.
If constructing, working, and testing on the Docker picture will not be tremendous time-consuming, I like to recommend additionally including this to the pre-commit hooks. This manner, you assure that earlier than you push any code, you’ve examined that the code runs in a manufacturing setting, and that you just get the anticipated output for a given enter. Implementing this as a pre-commit hook will possible prevent a number of time sooner or later.
Give Cursor entry to testing scripts
The second tip is that I at all times present Cursor and Claude Code entry to run my testing scripts. I then inform Cursor to run the testing scripts after making adjustments, and earlier than ending its present implementation.
Having your coding agent run and take a look at Docker pictures will vastly enhance the quantity of occasions it’s in a position to one-shot an implementation
This can prevent a number of time when your coding agent implements a function, after which you need to manually run and take a look at the Docker picture. If you happen to now encounter an error, you need to paste that into your coding agent, and the cycle repeats till the code is working.
This can be a waste of time, and one thing you must work onerous to keep away from. Giving your coding agent entry to the testing scripts is basically like handing your coding agent a device, which strongly improves efficiency in software program engineering duties. I can’t stress sufficient how a lot time this protects me.
Conclusion
On this article, I’ve mentioned how one can create lifelike manufacturing environments domestically by creating scripts to construct, run, and take a look at Docker pictures domestically. Doing this lowers iteration pace, which is a essential element of being an environment friendly programmer. Moreover, I coated how I do that in observe: by prompting Cursor to create the testing scripts, and a few instance occasions I can run on the Docker picture. I then give Cursor and Claude Code entry to run these scripts, making my programming vastly extra environment friendly.
I consider that having a fast iteration pace is essential for nearly all software program engineering duties, and it’s one thing you must attempt for. Creating native take a look at recordsdata and giving your coding agent entry to them will increase iteration pace loads, which is why I consider that doing so myself has vastly elevated my productiveness as a programmer.
👉 My Free Assets
🚀 10x Your Engineering with LLMs (Free 3-Day Email Course)
📚 Get my free Vision Language Models ebook
💻 My webinar on Vision Language Models
👉 Discover me on socials:
🧑💻 Get in touch
✍️ Medium

