Unitas, Martin Fowler, Cote discussed on DataFramed



Do you know what color unit test is? No. But I do know that I'm red green colorblind. It is a bit of a trick question. But your unit tests should be red green green listeners may recall that we've discussed unit tests in a previous segment. Awesome to recap unit. Tests are a key software engineering tool in our arsenal to make sure code is. Correct. They help you catch errors immediately as you write your code, and you can check if one of your rocket scientists coworkers push code, which broke the Bill righteous data. Something intas always run the unit test before pushing their changes to how does this magic happen been unit tests work by providing a framework that runs your code before the entire application is complete the framework will call your functions foreign. Cheat objects, and then check the desertions are true, which lets you find out immediately. If you coated your brilliant idea correctly when everything is still fresh in your mind and easiest to fix a good framework will even set up the resources to run a test such as a fake database or simulated data before calling your test. Those of you who heard the, and you Q segment on how to think about correctness of scientific models or recall that this is the verification step. And how you provide proof that your code correctly implements, the model so been do you have a favorite unit test framework in python checkout unit tests, and in our heavily wiccans test that really the most important thing is that you use a unit test framework look for the one which provides the least friction for you and your team. So what is this chromatic magic? You mentioned red green green is one of the best philosophies for writing unit tests and part of the test driven development approach the idea. Is to make the feedback loop on whether the code. You wrote is correct. As tight as possible. This will boost your productivity and increase the quality of your work essentially for free. So how does it work? The first read means that you should write your unit test code and write a stub for the function you want to test. Then when you run the unit test it should fail, hence the name read. This gives you confidence that your unit test will fail when the code doesn't work and the first green the first green means that you then implement the code and get the unit test to work at this stage. You only care about correctness. Don't forget canoes comment that premature optimization is the root of all evil in programming. Cool and the final green the final green means that now that your code and unit test work, you can refer back for it to make it faster cleaner or add other improvements because you have a unit test, you know, that you're optimizations which you should make only if necessary. Work correctly. Remember only reflector in the presence of working tests. Martin Fowler may have said something to that effect. I'm excited to try this out next time, I wrote some tests. Yeah. Once you start writing code this way, you will have much more confidence in your system and be more productive because unit Unitas naval you to catch most bugs sooner while you are first implementing the code buds are just easier to fix when you still have all the Cote stacked up in your head. Thanks been for that dive into test driven development..

Coming up next