Oct-18-2017, 12:04 PM
Hi,
I am learning unit testing.
The principle I am trying to adopt is to unit test only incoming queries for returned value and incoming commands for change of value plus outgoing command checking if it was sent with correct parameters (as per Sandi Metz lecture).
This cuts off unnecessary testing of private methods and redundant tests of the same code.
I am at a loss though how to classify an __init__ method that sets up publicly available attributes of a class...
Example:
MyClass(object):
def __init__(self, public_attr_1, public_attr_2)
self.public_attr_1 = public_attr_1
self.public_attr_2 = public_attr_2
Test:
instance = MyClass(1, 2)
assert instance.public_attr_1 = 1
assert instance.public_attr_2 = 2
My hunch is that it should be unit tested to make sure the class is initialized with correct attributes (the public ones).
Would you unit test it?
(Sorry for no formatting for code - it disappeared)
I am learning unit testing.
The principle I am trying to adopt is to unit test only incoming queries for returned value and incoming commands for change of value plus outgoing command checking if it was sent with correct parameters (as per Sandi Metz lecture).
This cuts off unnecessary testing of private methods and redundant tests of the same code.
I am at a loss though how to classify an __init__ method that sets up publicly available attributes of a class...
Example:
MyClass(object):
def __init__(self, public_attr_1, public_attr_2)
self.public_attr_1 = public_attr_1
self.public_attr_2 = public_attr_2
Test:
instance = MyClass(1, 2)
assert instance.public_attr_1 = 1
assert instance.public_attr_2 = 2
My hunch is that it should be unit tested to make sure the class is initialized with correct attributes (the public ones).
Would you unit test it?
(Sorry for no formatting for code - it disappeared)