# COMP0233 - Day 5 (3rd November 2022) :::info ## :tada: Welcome to the fifth day! Testing code with :snake: ### Today Today we will look at writing automated tests in Python. - Automating tests - Testing edge cases - Catching invalid inputs and testing that this behaves as expected - Testing in different setups - Avoid code repetition in your tests ::: ### Review from last week - :1234: Data and Python :snake: (csv, json, yaml) - :chart_with_upwards_trend: a bit about graphs #### What was discussed during the week :newspaper: - Sample solution for plotting exercise published :check: - Practical homework done by at least 11 people (count yesterday 11PM) - Assignment has been released, deadline: Wed 16 Nov 2022 at 16:00 (UK time) - Minor clarification on Moodle! ### Discussion of preparation work - testing terminology - on [Mentimeter](https://www.menti.com/9fi8o1xcxa). - homework consisted of writing a unit test for `times.py` - what else should be tested about `times.py` ([questionnaire](https://moodle.ucl.ac.uk/mod/questionnaire/view.php?id=2483635)) ### Exercise: Write more tests :::info For this exercise, we will continue working with the `times.py` that was part of the class preparation. In pairs, share a screen and discuss how to write the tests required. Then work collaboratively on the exercise. rse-classwork repo: [:hash::one::nine:](https://github.com/UCL-COMP0233-22-23/RSE-Classwork/issues/19) ::: ### Discussion: On [Mentimeter](https://www.menti.com/9fi8o1xcxa) Ask about things you were unsure of, and point out anything you found interesting or unexpected. ### Time for a short-movie :film_projector: What can happen when tests are lacking? ### Exercise: Write a negative test :::info Let's keep checking the robustness of this code! In pairs, share a screen, discuss how to write the required validation code, the negative test, and work collaboratively on the exercise. rse-classwork repo: [:hash::two::zero:](https://github.com/UCL-COMP0233-22-23/RSE-Classwork/issues/20) ::: ### Discussion of the exercise On [Mentimeter](https://www.menti.com/9fi8o1xcxa). Ask about things you were unsure of, and point out anything you found interesting or unexpected. ### Exercise: :construction_worker: Running the tests automatically :::info Continuous integration: Easy check that new contributions don't break stuff. In pairs, share a screen and work collaboratively on the exercise. rse-classwork repo: [:hash::two::one:](https://github.com/UCL-COMP0233-22-23/RSE-Classwork/issues/21) ::: ### Discussion of the exercise On [Mentimeter](https://www.menti.com/9fi8o1xcxa). Ask about things you were unsure of, and point out anything you found interesting or unexpected. ### Exercise: :sunny: DRYing the tests :::info Let's make these tests easier to manage! In smaller groups, share a screen, discuss how to write the required test, and work collaboratively on the exercise. rse-classwork repo: [:hash::two::seven:](https://github.com/UCL-COMP0233-22-23/RSE-Classwork/issues/27) ::: ### Discussion of the exercise On [Mentimeter](https://www.menti.com/9fi8o1xcxa). Ask about things you were unsure of, and point out anything you found interesting or unexpected. ### Feedback Please, fill the [mid-course feedback questionnaire](https://moodle.ucl.ac.uk/mod/questionnaire/view.php?id=4462960). ### Next... & Homework - Remaining exercises from week 5 - Preparation for week 6 ###### tags: `COMP0233` `teaching` `class`