Skip to main content

unitgen

Generate unit tests boilerplate code

This is a simple tool to generate boilerplate code for unit tests. It is for those developers who are not able to follow TDD (Test Driven Development) for few methods and want to write unit tests for them after writing the actual code.

All the test files are generated in a folder named "tests" if it does not exist.

Example: examples/calci.py

import math

class Calci:
    def __init__(self):
        print("Calci class created")

    def add(self, a, b=0):
        c = a + b
        return c

    def sub(self, a, b):
        return a - b


class StringCalci:
    def concat(self, a, b):
        return a + b

    def repeat(self, a, b):
        return a * b

Run unitgen from command line:

# View how to use unitgen
unitgen

# all files under examples directory are processed
unitgen examples

# Files calci.py and pay_handler.py are processed
unitgen examples/calci.py examples/pay_handler.py

Generated result: tests/test_calci.py

from unittest import TestCase
from examples.calci import Calci, StringCalci


class TestCalci(TestCase):
    def setUp(self):
        """ Set up objects for each test """
        
        self.calci = Calci()
    
    
    def test___init__(self):
        """ Test initialiser """
        self.obj = Calci()
    
    
    
    def test_add(self):
        
        a = None
        b = None
        actual_result = self.calci.add(a, b)
        expected_result = None
        self.assertEqual(actual_result, expected_result)
    
    
    
    def test_sub(self):
        
        a = None
        b = None
        actual_result = self.calci.sub(a, b)
        expected_result = None
        self.assertEqual(actual_result, expected_result)
    
    
    def tearDown(self):
        """ Destroy objects after each test """

class TestStringCalci(TestCase):
    def setUp(self):
        """ Set up objects for each test """
        
        self.string_calci = StringCalci()
    
    
    def test_concat(self):
        
        a = None
        b = None
        actual_result = self.string_calci.concat(a, b)
        expected_result = None
        self.assertEqual(actual_result, expected_result)
    
    def test_repeat(self):
        
        a = None
        b = None
        actual_result = self.string_calci.repeat(a, b)
        expected_result = None
        self.assertEqual(actual_result, expected_result)
    
    
    def tearDown(self):
        """ Destroy objects after each test """

Enjoy!

My Github profile: susmitpy

My Linkedin profile: susmit vengurlekar

My Medium profile: susmit.py

Metadata

Release files for unitgen 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unitgen 1.2
File Size Uploaded
unitgen-1.2.tar.gz 4.2 kB Details

Release files / unitgen-1.2.tar.gz

Download URL unitgen-1.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
55ad6304f83227e2bb3e7a5418ac3373a540e8aeed3178c9c620b41210d10f15
BLAKE2b-256 checksum
How to use checksums
d676f1641d97ee78e6272889302c72d94408a64f86e3a1cd732f0a296521d44b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/1.6.1 pkginfo/1.8.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.2 This release

1 release file

1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page