Basic unittest TestCase
<p>I have written the below code to test a basic unittest case for learning. When I execute the below code. I do not get any output. Could someone let me know what could be issue.</p>

<pre><code>import unittest
  class test123(unittest.TestCase):

    def test1(self):
      print "test1"

 if __name__ == "main":
 x=test123()
 x.test1()
 unittest.main()
</code></pre>

<p>In your test you need two things:</p>

<ol>
<li>Define your test function with 'test'</li>
<li>You need a expected result</li>
</ol>

<p>test.py</p>

<pre><code>import unittest

class TestHello(unittest.TestCase):

    def test_hello(self):  # Your test function usually need define her name with test
        str_hello = 'hello'
        self.assertEqual(str_hello, 'hello') # you need return a expected result

    def test_split(self):
        str_hello = 'hello world'
        self.assertEqual(str_hello.split(), ['hello', 'world'])

if __name__ == '__main__':
    unittest.main()
</code></pre>

<p>for execute use:</p>

<pre><code>python -m unittest test
</code></pre>

<p>out:</p>

<pre><code>stackoverflow$ python -m unittest test
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK
</code></pre>

python python-unittest