The Test Template Generator is a Python script that automates the creation of a template file containing unit test cases for functions in a given source file. It saves you time by generating the initial structure of test cases, allowing you to focus on writing test assertions and verifying the correctness of your code.
The original file was written by user hoefling in following answer as custom tool: Stackoverflow link
I've modified for my purpose and added some features, including putting function names and its argument in the testcase which we want to test. It will reduce some work on user's side. I'm planning to add more features.
- Automatically generates a template file with unit test cases for functions in a source file.
- For now, it supports only pytest test frameworks
- Provides customizable options to specify the output file name, and other settings.
- Allows you to easily add or modify test cases based on your requirements.
To run the Test Template Generator, you need to have Python installed on your system. Ensure you have a compatible version of Python installed.
- Clone this repository to your local machine:
git clone https://github.com/vmnit/testgen.git- Navigate to the project directory:
cd testgenTo generate a test template file, follow these steps:
- Prepare your source file containing functions that need unit test cases.
- Run the script with the following command:
python testgen.py -s <source_file.py> -o <test_source_file.py>Replace source_file.py with the actual path and name of your source file.
- The script will generate a test template file named test_source_file.py in the same directory as the source file.
- Open the test template file in your preferred text editor and customize the generated test cases according to your needs.
- Run the modified test template file using your chosen test framework to execute the test cases against your source code.
For more details and customization options, refer to the script's documentation.
Contributions to the Test Template Generator are welcome! If you encounter any issues or have suggestions for improvements, please submit them in the issue tracker. Before making a contribution, kindly review the contribution guidelines for instructions on how to get started.
This project is licensed under the MIT License. Feel free to use, modify, and distribute the code within the terms of the license.