Skip to content

Adding Tests to Unittest Framework

Kiri Choi edited this page Sep 4, 2017 · 3 revisions

This document guides you on how to add additional tests into pySBOL testing framework. This page is intended for developers only.

Caution

All modification on testing framework must be committed to develop branch of libSBOL not to pySBOL2 github. pySBOL2 github is intended for distribution only.

Directions

The file to be modified is unit_test.py.

To add tests, find the appropriate test class (or create one) and add new functions that does the testing. For example, if you want to add new tests on ComponentDefinitions, you can add the function under TestComponentDefinitions class.

If you are adding new class, make sure that you add that in the TestSuite. To do so, add the name of the test class in the list called test_list at the bottom. This list is used to incorporate all the test cases into a single test suite. Certain function names, e.g. setUp() or tearDown() are use by unittest module. The actual test happens through assert methods, e.g. assertEqual(a, b) which checks whether object a and b are equal. Check this page for more info.

That's it! It's that simple.

An Example

    def testSeqDisplayId(self):
        listseq_read = []
        doc = Document()
        doc.read(os.path.join(TEST_LOC_SBOL2, str(TEST_FILES_SBOL2[72])))

        # List of displayIds        
        listseq = ['CRP_b_seq', 'CRa_U6_seq', 'gRNA_b_seq', 'mKate_seq']
        
        for seq in doc.sequences:
            listseq_read.append(seq.displayId.get())
            
        self.assertItemsEqual(listseq_read, listseq)

This is a test that checks whether pySBOL can correctly read sequence displayIds. The test starts by creating sbol.Document() and reading a SBOL file. The function supplies a list of all sequence displayIds to compare against. In a for loop, the function creates a new list with sequence displayIds extracted from the Document object. Finally, the function compares the elements in lists are equal by using assertItemsEqual.

Clone this wiki locally