From d578c36ef97da3691aa187ab1a9145ffa53568f7 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 20 Dec 2023 00:49:44 +0000 Subject: [PATCH] Add daily email for 2023-12-18 Should you run static analysis on your tests? --- src/content/daily-email/2023-12-18.md | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/content/daily-email/2023-12-18.md diff --git a/src/content/daily-email/2023-12-18.md b/src/content/daily-email/2023-12-18.md new file mode 100644 index 00000000..7165103c --- /dev/null +++ b/src/content/daily-email/2023-12-18.md @@ -0,0 +1,29 @@ +--- +title: > + Should you run static analysis on your tests? +pubDate: 2023-12-18 +permalink: > + archive/2023/12/18/static-analysis-on-tests +tags: + - software-development + - php + - phpstan + - static-analysis + - automated-testing +--- + +I'm an advocate of both automated testing and static analysis but have mostly kept the two separate. + +I've typically not run PHPStan on my automated test files - ignoring them in my PHPStan configuration. + +As tests aren't production/implementation code, what's the benefit of analysing them? + +Recently, though, I've challenged this and, on some projects, started to run PHPStan on my test classes. + +Depending on what level PHPStan is running, the more changes you're likely to have to make to get your test classes to pass the static analysis, and whilst it results in more verbose and explicit code, I prefer that and being able to easily understand what it does rather than implicit. + +If you have a bug in your test, static analysis will potentially find that, too, making your test suite more robust. + +Looking at some large open-source PHP projects, they run static analysis on their test code. + +Presumably, they're benefiting from it, so I'll try it and see if I get the same.