Unit testing with xUnit practical

This is a lab of the UoE to utilizing xUnit framework to develop unit tests. The experience was inspired by the DNA sequences job. The class of the sequence as follows:

import sys
class Sequence:
    """ DNA sequence consisting of A, C, G, T sequences."""
    WEIGHTS = {'A': 131.2, 'C': 289.2, 'G': 329.2, 'T': 304.2} 
"""dict of str or unicode to float:nucleotide molecular weights"""

    def __init__(self, sequence=""):
     """Initialise Sequence with a string. The string must only
     contain letters in the set a,A,c,C,g,G,t,T.
     :param sequence: sequence
     :type sequence: str or unicode
    :raises AssertionError: if sequence contains an invalid letter
        assert Sequence.is_valid(sequence), \
            "Sequence should only contain A, C, G and T"
        self._nucleotides = sequence.upper()

Python code is in the Python directory.
src/sequence.py contains a Python implementation of Sequence.

To run the tests, and also generate an xUnit XML test report:

Checking the output of the XML test report:

These were the test cases in test_sequence.py:

import unittest
from sequence import Sequence
class SequenceTestCase(unittest.TestCase):
    def test_get_nucleotides(self):
        sequence_str = "GATTACCA"
        sequence = Sequence(sequence_str)
        self.assertEquals(sequence_str, sequence.nucleotides,
                  msg="Nucleotides returned were not those given")

    def test_get_weight(self):
        sequence = Sequence("G")
                            msg="Weight returned was unexpected")

    def test_calculate_weight(self):
        sequence = Sequence("G")
                             msg="Weight returned was unexpected")                            


About Julita Inca

Ingeniero de Sistemas UNAC, Magíster en Ciencias de la Computación PUCP, Magíster en Computación de Alto Rendimiento de la Universidad de Edimburgo, OPW GNOME 2011, Miembro de la GNOME Foundation desde el 2012, Embajadora Fedora Perú desde el 2012, ganadora del scholarship of the Linux Foundation 2012, experiencia como Admin Linux en GMD y Especialista IT en IBM, con certificaciones RHCE, RHCSA, AIX 6.1, AIX 7 Administrator e ITILv3. Experiencia académica en universidades como PUCP, USIL y UNI. Leader of LinuXatUNI Community, HPC Software Specialist at UKAEA, and reviewer of the Technological Magazine of ESPOL-RTE, and volunteering Linux training for MINSA Peru... a simple mortal, just like you!
This entry was posted in τεχνολογια :: Technology and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s