Python – Expect an exception using pytest

When you want to add a test to verify that an exception is raised, you can use pytest.raises() like this: When the code doesn’t raise an exception, you’ll see a test failed message like this: Example – Expect WordCounter to raise an exception I’m implementing the following WordCounter class using a test-driven approach. The first … Read more

Event-driven .NET: How to unit test code that depends on an event

Testing code with a dependency on an event can be tricky. You may be tempted to directly unit test the event handling method. However, that doesn’t prove that code under test is listening for the event. It’s better to really fire the event, and then test side effects of the event handling method. Firing the … Read more

The bottom-up principles of unit testing, refactoring, and pragmatism

After years of coding and reading dev books I’ve distilled my coding principles down into these three simple principles: unit testing refactoring pragmatism I write these down in my notebook and repeat them to myself on a daily basis. These are my coding principles. It’s important to know your principles. Your principles act as a … Read more