OOP features

The language supports object oriented programming features such as creating objects. The features provide the way to perform basic method testing. Advanced test scenarios for classes are not supported yet.

Static methods

Static methods can be tested like any other procedure.

class StaticMethods:
    x = 5
    y = 1

    def __init__(self, a, b):
        self.a = a
        self.b = b

    @staticmethod
    def sub(a, b):
        """
        spec:
            domain 10, 7: results 3
            # Check if creation of an object changes the result
            new 40, 32
            domain 10, 7: results 3
        """
        return a - b

Methods

To create an object new keyword is used. new keyword creates the object by passing arguments to the class constructor. It provides a way to realize the test scenario:

new_object = ClassName(constructor_arguments)
result = new_object.method(method_arguments)
assert result == expected_result

This test scenario allows to test methods as separate units independently of other methods of the class.

class SingleMethodWithoutDocs:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def add(self, c):
        """
        spec:
            # Test creation of object
            new 10, 20
            domain 2: results 32
            # Make sure object is replaced with a new one
            new -6, 2
            domain 4: results 0
        """
        return self.a + self.b + c

    def sub(self):
        """
        spec:
            new 20, 10
            domain : results 10
            new 40, 32
            domain : results 8
        """
        return self.a - self.b

    def mul(self):
        return self.a * self.b