Intermediate unit test: Difference between revisions
Jump to navigation
Jump to search
| Line 17: | Line 17: | ||
== Exercises to be handed in == | == Exercises to be handed in == | ||
You should make a special folder for the exercises. I will refer to my special folder as ''unittest'' in these exercises. You will also see some ''__pycache__'' folders appear in places. This is Pythons cache for "compiled" programs. It is safe to ignore and also to delete, because it may become outdated. | You should make a special folder for the exercises. I will refer to my special folder as ''unittest'' in these exercises. You will also see some ''__pycache__'' folders appear in places. This is Pythons cache for "compiled" programs. It is safe to ignore and also to delete, because it may become outdated. | ||
# Follow the file structure of having a ''code'' (or ''src'') folder for programs, a ''test'' folder for tests, and now a ''testdata'' folder for files containing test data. Now make unit tests and appropriate test data files for your '''fasta''' class from last week. In this exercise you just need to make unit test for the method '''load'''. You need to hand in both tests and test data.<br><br> | |||
# Add unit tests for the method '''save''' in your '''fasta''' class. Hand in same way as above.<br><br> | |||
# Add unit tests for the method '''delete''' in your '''fasta''' class. Hand in same way as above.<br><br> | |||
I would not be surprised if you find errors in your '''fasta''' class based on these tests. I found flaws in my code. | |||
== Exercises for extra practice == | == Exercises for extra practice == | ||
Revision as of 16:16, 14 April 2026
| Previous: Beginning unit test | Next: Runtime evaluation |
Required course material for the lesson
Powerpoint: Testing
Online: pytest documentation
Resource: Unit test - start of reverse polish notation class
Blog: On testing, by the founder of StackExchange.
Subjects covered
Unit test using pytest framework.
Files, test data
Setting up real projects
Exercises to be handed in
You should make a special folder for the exercises. I will refer to my special folder as unittest in these exercises. You will also see some __pycache__ folders appear in places. This is Pythons cache for "compiled" programs. It is safe to ignore and also to delete, because it may become outdated.
- Follow the file structure of having a code (or src) folder for programs, a test folder for tests, and now a testdata folder for files containing test data. Now make unit tests and appropriate test data files for your fasta class from last week. In this exercise you just need to make unit test for the method load. You need to hand in both tests and test data.
- Add unit tests for the method save in your fasta class. Hand in same way as above.
- Add unit tests for the method delete in your fasta class. Hand in same way as above.
I would not be surprised if you find errors in your fasta class based on these tests. I found flaws in my code.