Software Testing

You should verify every desired behavior of your project.

Tests exist to verify some behavior of the object being tested. Some tests can be manual, such as manually executing a program and verifying that the program works as you’d expect. When performing manual testing, the project requirements live in your head and aren’t particularly durable. If you return to a project months later, you might not know the desired behavior. Additionally, manual testing requires valuable time and effort to perform. Manual testing does not scale. As you add more functionality, you will need more time, discipline, and the ability to test your project’s behavior manually.

Automated tests help by explicitly defining the expected behavior, and it provides a way to run tests with near-zero manual effort. If the automated tests are easy to run, then you can quickly make a change, run the tests, and verify that your change worked as expected. If your automated tests have low coverage, you will have less confidence and resort to manual testing.

Your tests will essentially become the “source of truth” for the expected behavior of your project.

There are many forms of automated testing, to name a few: unit, integration, and end-to-end.

What kind of tests you should write largely depends on what type of software you’re testing. The classic testing pyramid would suggest that you write many unit tests. I think that this is entirely wrong.

Unit tests can be great if the project is well-architected and if the project is in a language that lends itself well to unit testing. I’ve had a great experience with unit testing in Java and absolutely terrible experiences with JavaScript.

Testing is essential, but that doesn’t mean you should dump unlimited time into it. You’ll catch the most bugs by running tests in an environment that is as close to production as possible. These are usually called integration tests or end-to-end tests.

The tradeoff is that being “closer to production” usually means “really hard or slow to run”.

So, what kind of tests should you write?

If the primary purpose of your project is to provide an API, you should write tests that check that your API contract is followed to the letter. You might want to have performance tests to ensure that it can have the desired response time.

If you’re writing a software library, you’ll want many unit tests to verify the behavior of the methods you expose. You might want some integration tests, but you might be able to get away without any.

For web applications, you should skip unit tests. Your application depends on the browser, so do your testing in a real browser. Communicate with real APIs and not mocks. You might want unit tests only for parts of your application that are not dependent on the browser or particularly tricky behavior.

Posts from blogs I like

Pikmin 3: No Fruit, No Problem - 0 Fruit in 2h24m

Want to watch this in your video player of choice? Take this: https://cdn.xeiaso.net/file/christine-static/video/2024/pikmin-3-0-fruit/2/index.m3u8 Recently I saw @TheBacklogs do a Pikmin 3 challenge run where they collected 0 fruit to beat the game. I thought I could do better, so I beat it in 2 hours 24 minutes. Full run without commentary: https://youtu.be/nHFIn74-mLk @TheBacklogs' run: https://youtu.be/eSEUdgVX7o4 My website: https://xeiaso.net My Mastodon: …

via Xe Iaso's blog May 04, 2024

Copyleft licenses are not “restrictive”

One may observe an axis, or a “spectrum”, along which free and open source software licenses can be organized, where one end is “permissive” and the other end is “copyleft”. It is important to acknowledge, however, that though copyleft can be found at the opposite end of an axis with respect to permissive, it is not synonymous with the linguistic antonym of permissive – that is, copyleft licenses are not “restrictive” by comparison with permissive licenses. Aside: Free software is not synonymous with copyle…

via Drew DeVault's blog April 19, 2024

Airfoil

The dream of soaring in the sky like a bird has captivated the human mind for ages. Although many failed, some eventually succeeded in achieving that goal. These days we take air transportation for granted, but the physics of flight can still be puzzling. In this article we’ll investigate what makes airplanes fly by looking at the forces generated by the flow of air around the aircraft’s wings. More specifically, we’ll focus on the cross section of those wings to reveal the shape of an airfoil – you can see…

via Bartosz Ciechanowski February 27, 2024