Testing: Note: the following code is written in Python using the unittest framew
ID: 3684021 • Letter: T
Question
Testing:
Note: the following code is written in Python using the unittest framework. However, this is not intended as a test of your Python knowledge. You may answer using any modern, object-oriented language. Python, Java, C++, C#, or even detailed pseudocode are all acceptable.
Consider the following test suite for a SUT (system under test) class:
import unittest
class MyTests(unittest.TestCase):
def setup(self):
sharedDOC.start( )
def test1(self):
sut = SUT( )
sut.invoke(1)
self.assertTrue(1==sut.state( ))
def test2(self):
sut = SUT( )
sut.invoke(2)
self.assertTrue(sut.state( ) == 2)
def tearDown(self):
sharedDOC.stop( )
Suggest a better way to write the assertions in the tests. Why is this better?
Explanation / Answer
It is better because:
Here multiple asserts are used to make sure complex conditions can be turned into the expected predicate.
While only testing one unit (the ToPredicate method), we can cover everything that can be thought of in the test..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.