<commit_before>---
layout: post
title: "Prove Your Code Works: Tests"
description: ""
tags: [code quality, documentation, tests, code analysis]
published: false
---
Tests are one of the most important ways to prove your code works, they enable observability and provide a guarantee code will work as expected. In general they are a professional approach to software development. 

Software tests are a vast and complex subject, made up of many different types of tests, such as Unit Tests, Integration Tests, Behavioral Tests, and many more. The Test Pyramid provides a useful overview of the subject but does not capture everything involved.

<img src="/assets/img/testing-pyramid.jpg" alt="Testing Pyramid">

Due to the complexity of the subject this post will focus on only three aspects of testing, Unit Tests, Code Coverage and Mutation Tests. It is felt these topics present the most value in terms of professionalism and proving code works.

## Unit Tests

Unit Tests are the basis of software testing as the majority of the tests a developer will write will be [Unit Tests](https://phpunit.de/). But how do we define a Unit Test? 

A Unit Test is a small test which tests an equally small amount of business logic. A suite of Unit Tests should run quickly as they only test isolated code. And while the line between Unit Tests and Integration Tests is blurry Unit Tests should never test frameworks, dependencies or Input / Output. 

<img src="/assets/img/application-structure.jpg" alt="Unit Tests and Application Structure">

The primary aim of Unit Tests is to ensure your core business logic functions as expected so you can prove it works. And this is achieved through the isolation of code, so each part can be proven to work independently of anything else.

There are two basic rules to follow to achieve code isolation.
<commit_msg>Set prove code tests article to publish and updated description.<commit_after>---
layout: post
title: "Prove Your Code Works: Tests"
description: "Tests are one of the most important ways to prove your code works, they enable observability and provide a guarantee code will work as expected."
tags: [code quality, documentation, tests, code analysis]
published: true
---
Tests are one of the most important ways to prove your code works, they enable observability and provide a guarantee code will work as expected. In general they are a professional approach to software development. 

Software tests are a vast and complex subject, made up of many different types of tests, such as Unit Tests, Integration Tests, Behavioral Tests, and many more. The Test Pyramid provides a useful overview of the subject but does not capture everything involved.

<img src="/assets/img/testing-pyramid.jpg" alt="Testing Pyramid">

Due to the complexity of the subject this post will focus on only three aspects of testing, Unit Tests, Code Coverage and Mutation Tests. It is felt these topics present the most value in terms of professionalism and proving code works.

## Unit Tests

Unit Tests are the basis of software testing as the majority of the tests a developer will write will be [Unit Tests](https://phpunit.de/). But how do we define a Unit Test? 

A Unit Test is a small test which tests an equally small amount of business logic. A suite of Unit Tests should run quickly as they only test isolated code. And while the line between Unit Tests and Integration Tests is blurry Unit Tests should never test frameworks, dependencies or Input / Output. 

<img src="/assets/img/application-structure.jpg" alt="Unit Tests and Application Structure">

The primary aim of Unit Tests is to ensure your core business logic functions as expected so you can prove it works. And this is achieved through the isolation of code, so each part can be proven to work independently of anything else.

There are two basic rules to follow to achieve code isolation.

{'fraction_non_alphanumeric': 0.04498714652956298, 'fraction_numerical': 0.0, 'mean_word_length': 4.480281690140845, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5661256', 'n_tokens_mistral': 888, 'n_tokens_neox': 865, 'n_words': 608}