> For the complete documentation index, see [llms.txt](https://ai-native-development.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-native-development.gitbook.io/docs/test/test-only-what-is-necessary.md).

# Test only what is necessary

Test only what is necessary, so that you can avoid the cost of maintaining unnecessary tests.

[![](https://img.shields.io/badge/Lv0-Pattern_Idea-blueviolet)](https://github.com/orgs/AI-Native-Development/projects/1/)

{% hint style="info" %}
There is no need to write unnecessary test cases, but it depends on the team what tests are needed. More specific discussion is needed to flesh this out as a pattern.
{% endhint %}

## Description

In the era of rapid software development, writing efficient and useful tests is more important than ever, and when using GitHub Copilot, developers may generate a lot of test code to increase coverage. However, unnecessary test code generation can lead to maintenance burdens and technical debt, so it is important to test only what is necessary when writing test code using GitHub Copilot.

### Example

Here's an example of how you might choose to write a meaningful test for a specific function rather than writing multiple tests just to boost coverage:

Here are some examples of possible unnecessary test codes:

* Testing Setters and Getters
* Testing Language Features
* Testing Framework Functionality
* Testing Constants
* Redundant Tests with Same Logic
* Testing Trivial Logic
* Testing Third-party Libraries
* Testing Random Values Without Logic

Rather than adding numerous tests that only increase coverage without adding value.

## Exerecise

* **Exercise 1**: Identify a function in your codebase that is currently over-tested with meaningless tests and refactor it to only include necessary tests.
* **Exercise 2**: Write a new test for a critical part of your code, focusing only on the crucial aspects, avoiding redundancy.
* **Exercise 3**: Evaluate your current test coverage and identify areas where tests can be reduced without losing essential coverage.

## Checklist for Further Learning

* Are you writing tests that truly validate the functionality, or am I writing tests just to increase coverage?
* How can you ensure that the tests I'm writing are providing value to the project and not just adding to the maintenance burden?
* What strategies can you adopt to keep my test suite lean and meaningful, especially when using tools like GitHub Copilot?


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ai-native-development.gitbook.io/docs/test/test-only-what-is-necessary.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
