Changes for page Tips and Tricks
Last modified by chrisby on 2024/04/01 13:11
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,4 +1,4 @@ 1 -* **Regularity:** Run tests regularly, ideally before every commit, for optimal quality assurance. In particular, run all relevant tests before pushing code or creating a pull/merge request. Continuous integration practices are helpful for enforcing testing of code uploaded by other developers. 1 +* **Regularity:** Run tests regularly, ideally before every commit, for optimal quality assurance. In particular, run all relevant tests before pushing code or creating a pull/merge request. 'Continuous integration' practices are helpful for enforcing testing of code uploaded by other developers. 2 2 * Use **functional programming** for data processing tasks because it is less prone to errors and side effects. 3 3 * It's common to create **test users and test data** to facilitate the testing process. 4 4 * Don't reinvent the wheel and **use existing test libraries**. There are proven solutions that minimize the effort of creating tests. ... ... @@ -15,7 +15,7 @@ 15 15 * **Avoid files** 16 16 ** I/O is slow increasing the test time unnecessarily. 17 17 ** Temporary files may persist because you forgot to delete them or put them in folders where they will never be found. At the very least, be sure to delete files at the very beginning of the test to ensure their absence. Deleting files at the end of a test is prone to erros because if the test fails/aborts, those files may persist and affect subsequent tests. 18 -** Prefer data streams over files. 18 +** Prefer data streams over files for testing. 19 19 * **Don't leave tests unfinished**, don't just comment out @Test (annotation in Java to mark a function as a test), and don't leave empty test bodies as these things are confusing and waste the reader's time. If you come across this kind of code, try to learn its purpose, ask people who worked on it, and rebuild it. If that is not possible or worth the time, then delete it as the dead code that it is. To indicate that tests need to be implemented, an issue/work unit could be created and referenced, or a TODO comment with an explanatory description could be added. 20 20 * **A test should fail if an expected exception is not thrown.** Test libraries usually have methods to handle such cases. If the exception object must be examined, use a try-catch block that includes a fails() method at the end of the try block. Without the fails() method to make the test fail, the test would wrongfully pass if no exception were thrown: 21 21 ... ... @@ -29,7 +29,7 @@ 29 29 {{/code}} 30 30 31 31 * **Different branches** of production code should be checked in different tests. 32 -* **Avoid if-statements in the test code**, but at least be careful with assertions in if/if-else blocks, as the test may pass without executing them. To prevent this, add 'else{fails()}'attheend, or assertthe conditionand branch:32 +* **Avoid if-statements in the test code**, but at least be careful with assertions in if/if-else blocks, as the test may pass without executing them. To prevent this, here are a few suggestions: 33 33 34 34 {{code}} 35 35 // bad - still passes when x == false and y == false