Cris
Cris

Reputation: 11

How to write unit test to this method

I have such an example of method:

class Class(OtherClass):
    def __init__(self, x):
        self.x = x

or the second example:

class Class():
    def __init__(self, x):
        self.x = x

I have no idea how to write a unit test to verify it. I have experience only in classic functions like:

def add(x,y):
    return x + y

Thanks a lot for help.

Upvotes: 0

Views: 54

Answers (1)

Rob
Rob

Reputation: 3513

You have just written a class definition with a single method, which is called when the class is instantiated. So a unit test could be if you can instantiate the object and check if its attribute is correct.

testx = 'something'
assert Class(testx).x == testx

Upvotes: 1

Related Questions