-
Notifications
You must be signed in to change notification settings - Fork 42
Aut2026review batch2 #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mmesiti
wants to merge
24
commits into
coderefinery:main
Choose a base branch
from
mmesiti:aut2026review-batch2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Aut2026review batch2 #252
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
319d791
Vocabulary from motivation to quick reference
mmesiti 03bf5d9
Fix "what can test help you do?" section
mmesiti bdbe948
moved recommendations to the conclusions
mmesiti b13270d
Add comment on self-hosting
mmesiti afad9c8
Small rewording fixes
mmesiti e68959f
Completely remove "where to start" from motivation
mmesiti 4fd8d0d
Elaborate on runner self-hosting
mmesiti 17a80d2
Motivations: small reformatting for readability
mmesiti 52aae85
fix typo
mmesiti 5cfed98
Use epigraph directive for quote in motivations
mmesiti 598f314
Motivations: refactor + frameworks
mmesiti f5d4062
Fixes from Anja's review
mmesiti 6a2db30
move "why use a testing framework" to conclusions
mmesiti 5a068cf
mention e2e and unit test in examples in motivations
mmesiti 3189516
Some addition to conclusions and quick reference
mmesiti 04abe9a
modularity <-> testability in conclusions
mmesiti d481962
Lots of fixes by Anja
mmesiti c70cdf9
further sphinx warning fixes
mmesiti 906dea2
(minor) terser / better wording
mmesiti 77f7b50
conclusions: Improve wording on knowledge needed
mmesiti 084c7a1
conclusions: test framework feat table col fixes
mmesiti a187734
Mention the test pyramid
mmesiti ce9039a
Split 'Exercise' in local testing in 2 sections
mmesiti dfb8fb7
local testing: false negative -> false positive
mmesiti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,174 @@ | ||
| # Conclusions and recommendations | ||
|
|
||
| ## The basics | ||
| ```{objectives} | ||
| - What is a realistic approach to automated test? | ||
| - How can I start? | ||
| ``` | ||
|
|
||
| - Learn one test framework well enough for basics | ||
| - Explore and use the good tools that exist out there | ||
| - An incomplete list of testing frameworks can be found in the [Quick Reference](quick-reference) | ||
| - Start with some basics | ||
| - Some simple thing that test all parts | ||
| - Automate tests | ||
| - Faster feedback and reduce the number of surprises | ||
| --- | ||
|
|
||
| ## Discussion: What's easy and hard to test? | ||
|
|
||
| ## Going more in-depth | ||
| ```{discussion} Discussion: Testing in practice | ||
|
|
||
| Use the collaborative notes to answer these questions: | ||
|
|
||
| 1. Give examples of things (from your work) that are easy to test. | ||
| 2. Give examples of things (from your work) that are hard to test. | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| Considering automated tests when writing code | ||
| is a major mental shift, that you will hopefully embrace | ||
| after attending this lesson. | ||
|
|
||
| ## The basics: what knowledge do you need? | ||
|
|
||
| Learn one {term}`testing framework` well enough for basics: | ||
| - Explore and use the good tools that exist out there. | ||
| - An incomplete list of testing frameworks | ||
| can be found [here](#unit-test-frameworks). | ||
|
|
||
| ### Why use a testing framework? | ||
|
|
||
| Automated testing typically involves a number of repetitive tasks | ||
| and tricky problem solving. | ||
|
|
||
| Fortunately for us, | ||
| someone has already found a solution for most of these | ||
| and created {term}`testing framework`s that we can use. | ||
|
|
||
| Note: not all frameworks solve all problems | ||
| (also because sometimes the underlying language does not have the necessary features). | ||
|
|
||
| ```{list-table} Why use a testing framework? | ||
| :widths: 40 40 20 | ||
| * - **Typical problem** | ||
| - **Solution** | ||
| - **Examples** | ||
| * - Report failures/successes | ||
| consistently | ||
| (to humans or other machines) | ||
| - Automated collection and output, | ||
| (e.g., Junit XML format or [TAP](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) | ||
| - Fundamental feature that | ||
| all testing frameworks have | ||
| * - Remember to run | ||
| all the tests you write | ||
| in the main test script/program | ||
| - Automatic discovery, | ||
| automatic {term}`registration<test registration>` | ||
| when declaring test functions | ||
| - [pytest](https://docs.pytest.org/en/stable/) | ||
| * - Run only some tests | ||
| (to save time) | ||
| - Test filtering | ||
| via patterns | ||
| - [pytest](https://docs.pytest.org/en/stable/how-to/usage.html#specifying-which-tests-to-run) | ||
| * - Provide useful information | ||
| on why a test has failed | ||
| - "Smart" assertions/macros | ||
| - [pytest](https://docs.pytest.org/en/stable/how-to/assert.html#assert), | ||
| [GoogleTest](https://google.github.io/googletest/primer.html#assertions) | ||
| * - Run same test for many | ||
| known input/output combinations | ||
| - Parametric tests | ||
| - [pytest](https://docs.pytest.org/en/stable/how-to/parametrize.html#pytest-mark-parametrize-parametrizing-test-functions), | ||
| [Julia](https://docs.julialang.org/en/v1/stdlib/Test/#Working-with-Test-Sets) (see `testset for`) | ||
| * - Check that a property holds | ||
| for a class of inputs and outputs | ||
| - Automatically generate test cases | ||
| based on a strategy | ||
| (property testing) | ||
| - [hypothesis](https://hypothesis.readthedocs.io/en/latest/tutorial/introduction.html) | ||
| (Python) | ||
| * - Debugging on failure | ||
| - Start debugger on test failure | ||
| - `pytest --pdb` | ||
| * - Floating point equalities | ||
| with tolerance | ||
| - Macros/classes | ||
| - `≈` (Julia), `pytest.approx` | ||
| * - Set up and tear down | ||
| of complex test cases | ||
| - {term}`Fixture`s | ||
| - [pytest](https://docs.pytest.org/en/stable/explanation/fixtures.html), | ||
| [GoogleTest](https://google.github.io/googletest/primer.html#same-data-multiple-tests) | ||
| * - Estimate how much of your code | ||
| is *run* in the test suite | ||
| - Automatic {term}`coverage<code coverage>` | ||
| measurement | ||
| - [Pytest-cov](https://pytest-cov.readthedocs.io/en/latest/), | ||
| [gcov/lcov](https://wiki.cs.jmu.edu/reference/gcov/) | ||
| (for C/C++/Fortran) | ||
| * - Do code examples | ||
| in documentation | ||
| work as expected? | ||
| - Documentation tests | ||
| (doctests) | ||
| - [Python](https://docs.python.org/3/library/doctest.html), | ||
| [Julia](https://documenter.juliadocs.org/stable/man/doctests/), | ||
| [R](https://cran.r-project.org/web/packages/doctest/vignettes/doctest.html) | ||
| * - Will my code work | ||
| with different versions | ||
| of the dependencies? | ||
| - Test in different environments | ||
| - [tox](https://tox.wiki/en), [Nox](https://nox.thea.codes/en/stable/index.html) | ||
| (Python) | ||
| ``` | ||
|
|
||
| - Strike a healthy balance between unit tests and integration tests | ||
| - As the code gets larger and the chance of undetected bugs | ||
| increases, tests should increase | ||
| - When adding new functionality, also add tests | ||
| - When you discover and fix a bug, also commit a test against this bug | ||
| - Use code coverage analysis to identify untested or unused code | ||
| - If you make your code easier to test, it becomes more modular | ||
|
|
||
| ## Don't over-test | ||
|
|
||
| ## Ways to get started | ||
| - Not every code needs perfect {term}`test coverage<code coverage>`. | ||
| - A simple script or notebook probably does not need an automated test. | ||
|
|
||
| ## Pick the low-hanging fruits first | ||
|
|
||
| You probably won't do everything perfectly when you start off... But | ||
| what are some of the easy starting points? | ||
|
|
||
| - Do you have some single functions that are easy to test, but hard to | ||
| verify just by looking at them? Add unit tests. | ||
| **If you have got nothing yet**: | ||
| 1. Start with an end-to-end test. | ||
| Typically easy to add, from a "manual" use case. | ||
| This should match (or serve as) an **example in the code documentation** anyway. | ||
| - Describe in words how *you* check whether the code still works. | ||
| - Translate the words into a script. | ||
| - Run the script as often as reasonable. | ||
|
|
||
| - Do you have data analysis or simulation of some sort? Make an | ||
| end-to-end test with sample data, or sample parameters. This is | ||
| useful as an example anyway. | ||
| 2. Do you have some single functions that are easy to test, but hard to | ||
| verify just by looking at them? Add unit tests. | ||
|
|
||
| - A local testing framework + GitHub actions is very easy! And works | ||
| well in the background - you do whatever you want and get an email | ||
| 3. A local testing framework + GitHub actions/Gitlab CI-CD is very easy! | ||
| And works well in the background - you do whatever you want and get an email | ||
| if you break things. It's actually pretty freeing. | ||
|
|
||
| **If you need to start modifying some existing code:** | ||
| 1. Add a {term}`characterization test` for the part of the code you need to change. | ||
| 2. Add tests for any functionality you intend to add. | ||
| 3. Consider adding some end-to-end tests for the use case you have in mind. | ||
|
|
||
| ## Going more in-depth | ||
|
|
||
| **With time**: | ||
| - The code gets larger, | ||
| the chance of undetected bugs increases, | ||
| tests should increase. | ||
| - Bugs will be found. When you find them, add tests against those. | ||
|
|
||
|
|
||
| **How to improve your code:** | ||
| - Use {term}`code coverage` analysis to identify untested or unused code. | ||
| Remember [Goodhart's Law](https://en.wikipedia.org/wiki/Goodhart%27s_law). | ||
| - Strike a healthy balance between different kinds of tests: | ||
| - Fast tests give you information quicker but can be shallow; | ||
| - Thorough tests can catch more bugs but take longer to run | ||
| and can be brittle. | ||
|
|
||
| The {term}`test pyramid` | ||
| is a recommended strategy to balance between test types. | ||
|
|
||
| - If you make your code easier to test, it becomes more modular (and vice versa - see the [modular code development lesson](https://coderefinery.github.io/modular-type-along/)). | ||
| - **Learning how to test well make the rest of your code better, too.** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this note below the table (now we are giving a note about problems before we present the problems in the table)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue against this just because this table is not meant to be discussed in detail, it's more there as a collection of reasons why one should use a testing framework. The message "... but not all frameworks tackle all the problems" is perhaps more important than the details contained in the table.
Perhaps, we should move the whole table to an appendix (or just the "quick-reference" episode, which isn't that quick anymore), put a link here, and go through it if permits? Not sure about that though.