Skip to content

Instantly share code, notes, and snippets.

@ronilpatel
Forked from k0emt/Experiment.py
Last active December 20, 2022 16:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ronilpatel/4b28e0f821ef119c8a8d223c89987f8a to your computer and use it in GitHub Desktop.
Save ronilpatel/4b28e0f821ef119c8a8d223c89987f8a to your computer and use it in GitHub Desktop.
Basic Hello world in Python with corresponding unittest
__author__ = 'k0emt'
class Greeter:
def __init__(self):
self.message = 'Hello world'
# print self.message
__author__ = 'k0emt'
import unittest
from Experiment import Greeter
class MyTestCase(unittest.TestCase):
def test_default_greeting_set(self):
greeter = Greeter()
# this test will fail until you change the Greeter to return this expected message
self.assertEqual(greeter.message, 'Hello world!')
# this test will fail if the Greeter does not return anything
self.assertIsNotNone(greeter.message)
# this test will fail if the Greeter's instance is not the same as that of the class 'str'
self.assertIsInstance(greeter.message, str)
if __name__ == '__main__':
unittest.main()
@ronilpatel
Copy link
Author

You can add more basic test cases that are ideal for the beginners such as :

  • checking for the None

  • checking for instance equality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment