Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote