A
A
Alexander2018-05-21 21:09:44
Python
Alexander, 2018-05-21 21:09:44

Python how to properly test a class with the unittest module?

Hello !
Decided to get to testing in python.
There is such a script.

"""Пример"""
import unittest

class Hello:
    def __init__(self):
        self.value = ""
        
    def name(self, value):
        self.value = value
        
    def show(self):
        if self.name == "":
            return "Hello user!"
        else:
            return str("Hello " + self.value + "!")

if __name__ == '__main__':
    hello = Hello()
    hello.name("Александр")
    print(hello.show())

Could you use this example to show how to properly test a class with all possible tests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elmo Sputterspark, 2018-05-21
@Sputterspark

If the code consists of shit and sticks, then three tests are needed - for shit, for sticks and integration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question