Skip to main content

Generate unit tests boilerplate code

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unitgen-1.2.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file unitgen-1.2.tar.gz.

File metadata

  • Download URL: unitgen-1.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for unitgen-1.2.tar.gz
Algorithm Hash digest
SHA256 55ad6304f83227e2bb3e7a5418ac3373a540e8aeed3178c9c620b41210d10f15
MD5 e8e4b6d022718321ffdb13487a65614e
BLAKE2b-256 d676f1641d97ee78e6272889302c72d94408a64f86e3a1cd732f0a296521d44b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page