DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Python Unit Test with unittest


Suppose there is such a test module:

$ cat src/test/py/test_input.py
import unittest
import sys

sys.path.append('src/main/py')
from com.dhcc.gics.driver.PythonDriver import run_app    # nopep8


class TestInput(unittest.TestCase):
    def test_sample_input(self):
        modelfile = """[
                      {
                        "stepId": "InputData",
                        "stepName": "Sample数据输入",
                        "stepType": "SampleInputStep",
                        "parameters": {
                          "url": "some sample data"
                        },
                        "ancestors": [],
                        "descendants": []
                      }
                    ]"""
        res = run_app(modelfile, "demoapp")
        self.assertEqual(3, res.count())
        self.assertAlmostEqual(32.7, res.head().asDict()['value'], places=4)

Run all test cases in a module: python -m unittest src.test.py.test_input.

Run a specific test case in a module: python -m unittest src.test.py.test_input.TestInput.test_sample_input.



Published

Jan 24, 2018

Last Updated

Jan 24, 2018

Category

Tech

Tags

  • python 136
  • unittest 4

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor