Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Making Changes and Triggering Automated Tests

Give Feedback

In this video, you’ll learn the basic concept of Test Driven Development (TDD) and apply it to your calculator project. Furthermore, a quick overview about further settings you can take in the CircleCI web interface is given.

Note: If you want to learn more about TDD, make sure to check out our course about Test-Driven Development With PyTest!

00:00 Now it’s time to add multiplication and division to your calculator library. Unlike last time, you’ll add the test before you write the function. Writing failing tests and then adding code to make them pass is called test driven development, which is a cool way to do things because it makes you think about your code and what it should do or not do before you start writing it out.

00:20 Back to your editor, go to test_calculator and write a test for multiplication that’s just called test_multiplication(self): and then assert that 100 is equal to the result of calculator.multiply(10, 10).

00:46 Save this, do a git add -A (all) and then git commit with the message 'add test for multiplication'.

01:01 Commit that and send it to GitHub!

01:08 Okay. Since CircleCI is watching this, this should trigger a build. So if I go back to CalculatorLibrary, you can see here’s the build running.

01:30 And I just got the notification, so let me open this up. And there you go. You can see that the build failed, and if you go down and you go to run tests, and you can see addition passed, subtraction passed, but multiplication failed. And it’s pretty clear why—because it has no attribute 'multiply', so it’s time to go ahead and add that!

01:50 Back to the editor, go to calculator.py,

01:56 and define multiply() with a first_term and a second_term like so. And you can just return first_term * second_term.

02:13 Save that,

02:17 add it to your repo by adding it, committing it. I’ll just say 'add multiply function',

02:29 and push it. Okay! Back to CircleCI. Let’s go back to CalculatorLibrary and you can see there’s a new job that’s running for adding the multiply function.

02:44 Let’s open this one up—and look at that, SUCCESS! Let’s go back down to run tests and you can see now test_multiplication passes.

02:54 So, there you go! You should be getting the hang of this by now, so go ahead and try to add a test for division to make the build fail, and then go ahead and add in the function to make it pass.

03:06 These have been relatively quick builds in this example, but sometimes it can take quite a while for all the tests to run through. The nice thing with using an external service like CircleCI is that you can work on something else while the build is being checked.

03:20 I have my account set up to send me emails if a build fails so I can do something else and then come back once it’s ready. There are other options too, so if you click on the little settings button, you can go down to Chat Notifications and you can integrate it with Slack or IRC.

03:35 Another cool thing with CircleCI is how it integrates back into GitHub. If we go back to the repo on here—and let me refresh this because we’ve added some more commits—and if you click on your commits, you’ll actually see check marks and x’s where a build failed or a build succeeded.

03:53 This can be a very quick way on GitHub to go back and see what actually caused—what new code was added to cause this to fail. Okay! So, that’s a quick overview of how to put CI into some of your projects. In the next video, we’ll wrap up by seeing what some of the next steps you can take are. Thanks for watching.

Become a Member to join the conversation.