LLM agent to facilitate the generation of unit test cases.
Project description
langunittest: Your Command-line LLM agent for unit test cases.
Problem
From clippy, you can generate unit test cases for Python modules with ease.
Take the following math.py module as an example:
def add(a: float, b: float) -> float:
return a + b
def div(a: float, b: float) -> float:
if b == 0.0:
raise ValueError('Invalid divisor!')
return a / b
You can generate unit test cases using the following command:
$ pack math.py | clippy 'Create unit test cases for "math.py".'
Example AI response:
import unittest
from math import add, div
class TestMathFunctions(unittest.TestCase):
# Test cases for add()
def test_add_positive_numbers(self):
self.assertAlmostEqual(add(1, 2), 3)
def test_add_negative_numbers(self):
self.assertAlmostEqual(add(-1, -2), -3)
def test_add_mixed_numbers(self):
self.assertAlmostEqual(add(-1, 2), 1)
self.assertAlmostEqual(add(1, -2), -1)
def test_add_with_zero(self):
self.assertAlmostEqual(add(5, 0), 5)
self.assertAlmostEqual(add(0, 0), 0)
def test_add_float_numbers(self):
self.assertAlmostEqual(add(0.1, 0.2), 0.3)
self.assertAlmostEqual(add(1.5, 2.5), 4.0)
# Test cases for div()
def test_div_positive_numbers(self):
self.assertAlmostEqual(div(6, 2), 3)
def test_div_negative_numbers(self):
self.assertAlmostEqual(div(-6, -2), 3)
def test_div_by_zero(self):
with self.assertRaisesRegex(ValueError, 'Invalid divisor!'):
div(10, 0)
with self.assertRaisesRegex(ValueError, 'Invalid divisor!'):
div(0, 0)
if __name__ == '__main__':
unittest.main(argv=['first-arg-is-ignored'], exit=False)
Current Limitations: Despite the convenience, this approach comes with several drawbacks:
- ⚠️ The generated test cases are printed to the console and must be copied manually into a file.
- ❌ The test cases may contain errors and are not always executable out of the box.
- 🧠 There’s no memory or iterative refinement; you cannot adjust or fine-tune the generated tests interactively.
- 📉 Test coverage of the generated code is not reported or optimized.
Introducing langunittest
To address these limitations, we propose langunittest, a module designed to provide an interactive agent that works with you to generate, refine, and validate unit tests more efficiently.
Key benefits include:
- 💾 Output saved directly to files—no copy-paste needed.
- ✅ Automatically verified executable test cases.
- 🔄 Interactive back-and-forth refinement with memory and state.
- 📈 Built-in test coverage analysis to ensure sufficient coverage.
With langunittest, the goal is to generate reliable, high-quality, and maintainable unit test suites through an iterative and intelligent workflow.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langunittest-0.1.0.tar.gz.
File metadata
- Download URL: langunittest-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-24-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e289ec87b8e8b5d7ec891c6830a1dd1b4ceb1c20b1c7ae04451bb034a28ee991
|
|
| MD5 |
1d811df2b7e35185e2b96a3f0dc0b4fd
|
|
| BLAKE2b-256 |
5bbef7c799b1b42f4f65c7731abeee68926ee4106b558310a71a41ac7cd2c3b1
|
File details
Details for the file langunittest-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langunittest-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-24-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9d6d3a3135769e7cf4056c96dfc9ae21f13c5a4b8e23f78167385c6affa8619
|
|
| MD5 |
c828d36703beb1b4faff889555e6a3a5
|
|
| BLAKE2b-256 |
070686dc498970d80d11484642da5ca83013798b7d6ac48a8c7d81278183d522
|