sayan801 / pyccda

A Python library for CCDA XML files. Part of the BlueButton health information liberation initiative.
1 stars 0 forks source link

python unit testing framework #10

Closed cribello closed 7 years ago

backup1-technicise commented 7 years ago

I read unittesting module from pythom to perform unit testing of my code. In addition, I also read different types of assert methods from TestCase to perform unit testing.

backup1-technicise commented 7 years ago

I am adding a simple code of python unit testing with log file...

sayan801 commented 7 years ago

Unit Test Tutorial

Library

sayan801 commented 7 years ago

I ran the the test file.. It is just creating a empty file not logging any thing yet...

chandra@chandraLapi:~/code/pyccda/abhisek$ python My_CCDA_test.py 
backup1-technicise commented 7 years ago

unittest module is read from following link https://docs.python.org/2/library/unittest.html unittest with log file creation is read from following two links: http://testfixtures.readthedocs.io/en/latest/logging.html https://docs.python.org/2/howto/logging.html

sayan801 commented 7 years ago

I am following tutorial (http://docs.python-guide.org/en/latest/writing/tests/) .. created a new file.. image

chandra@chandraLapi:~/code/pyccda/abhisek$ py.test
The program 'py.test' is currently not installed. You can install it by typing:
sudo apt install python-pytest
chandra@chandraLapi:~/code/pyccda/abhisek$ sudo apt install python-pytest
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-headers-4.4.0-34
  linux-headers-4.4.0-34-generic linux-image-4.2.0-42-generic
  linux-image-4.4.0-31-generic linux-image-4.4.0-34-generic
  linux-image-extra-4.2.0-42-generic linux-image-extra-4.4.0-31-generic
  linux-image-extra-4.4.0-34-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  python-py
Suggested packages:
  subversion python-pytest-xdist python-mock
The following NEW packages will be installed:
  python-py python-pytest
0 upgraded, 2 newly installed, 0 to remove and 52 not upgraded.
Need to get 182 kB of archives.
After this operation, 881 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 python-py all 1.4.31-1 [62.5 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 python-pytest all 2.8.7-4 [119 kB]
Fetched 182 kB in 1s (106 kB/s)        
Selecting previously unselected package python-py.
(Reading database ... 339219 files and directories currently installed.)
Preparing to unpack .../python-py_1.4.31-1_all.deb ...
Unpacking python-py (1.4.31-1) ...
Selecting previously unselected package python-pytest.
Preparing to unpack .../python-pytest_2.8.7-4_all.deb ...
Unpacking python-pytest (2.8.7-4) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python-py (1.4.31-1) ...
Setting up python-pytest (2.8.7-4) ...
chandra@chandraLapi:~/code/pyccda/abhisek$ py.test
============================= test session starts ==============================
platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /home/chandra/code/pyccda/abhisek, inifile: 
collected 2 items 

My_CCDA_test.py .
chandra_test.py F

=================================== FAILURES ===================================
_________________________________ test_answer __________________________________

    def test_answer():
>       assert func(3) == 5
E       assert 4 == 5
E        +  where 4 = func(3)

chandra_test.py:8: AssertionError
====================== 1 failed, 1 passed in 0.02 seconds ======================
chandra@chandraLapi:~/code/pyccda/abhisek$ 
backup1-technicise commented 7 years ago
  1. Put all the files below in a folder: Employees.json My_unit_testing_using_unittest.py Reg_exp_Emp_fields.py
  2. Run the following commands: cd $ python My_unit_testing_using_unittest.py Unfortunately, I am getting error. please help me..