jeudi 4 février 2016

Is it ok to import other classes in a unittest?

First of all, I have never written unit-tests before, so maybe this question is "stupid".

I have a class Node (add_node.py) in which I create nodes that connect to a websocket. Now I want to write unit-tests for checking whether or not the connection was successful, and for checking the response of the server.

So I created a node_tests.py file which the following content:

import unittest
import json
import re
from add_node import Node

class TestNodes(unittest.TestCase):

    def test_node_creation(self):
        self.node = Node(a='1', b='2', c='abc')
        self.response = json.loads(self.node.connect())
        self.assertIn('ok', self.response['r'])

if __name__ == '__main__':
    unittest.main()

This is working, but I'm not sure if that's the correct way of implementing it. The idea is to now write other methods for checking for instance if c='abc' or similar things, all withing the TestNodes class

Aucun commentaire:

Enregistrer un commentaire