=====================
Unit Testing Features
=====================

    >>> from z3c.feature.core import interfaces, unittest

Testing Feature
---------------

The testing feature provides automated testing hook up.

    >>> feature = unittest.TestingFeature()
    >>> from zope.interface.verify import verifyObject
    >>> verifyObject(interfaces.ITestingFeature, feature)
    True

    >>> print feature.featureTitle
    Automated Tests

We can also convert this to xml.

    >>> print feature.toXML(True, True)
    <feature type="z3c.feature.core:unit-testing"/>

Let's see how the testing feature modifies the project builder.  First
it adds buildout parts for running the tests, with and without
coverage reports and for generating coverage reports.

    >>> from z3c.builder.core.project import BuildoutProjectBuilder
    >>> project = BuildoutProjectBuilder(u'someproject')

    >>> feature.applyTo(project)

    >>> project.update()
    >>> print project.buildout.render()
    [buildout]
    extends = http://download.zope.org/zope3.4/3.4.0/versions.cfg
    develop = .
    parts = test coverage-test coverage-report
    versions = versions
    <BLANKLINE>
    [test]
    recipe = zc.recipe.testrunner
    eggs = someproject [test]
    <BLANKLINE>
    [coverage-test]
    recipe = zc.recipe.testrunner
    eggs = someproject [test]
    defaults = ['--coverage', '${buildout:directory}/coverage']
    <BLANKLINE>
    [coverage-report]
    recipe = zc.recipe.egg
    eggs = z3c.coverage
    scripts = coverage=coverage-report
    arguments = ('coverage', '${buildout:directory}/coverage/report')

Next it also modifies setup.py to add an extras requires section.

    >>> project.setup.extras_requires
    {'test': ['z3c.coverage', 'zope.testing']}

It also adds a tests package with a test_doc module that hooks up
doctests.

    >>> print project.package['tests']['test_doc.py'].render()
    import unittest
    import zope.testing.doctest
    <BLANKLINE>
    def test_suite():
        return unittest.TestSuite((
    <BLANKLINE>
            zope.testing.doctest.DocFileSuite(
                '../README.txt',
                optionflags=zope.testing.doctest.NORMALIZE_WHITESPACE |
                            zope.testing.doctest.ELLIPSIS),
    <BLANKLINE>
    <BLANKLINE>
            ))

Finally there is also a sample doctest file.

    >>> print project.package['README.txt'].render()
    ================
    A Simple DocTest
    ================
    <BLANKLINE>
    Doctests work by evaluating txt documents that look like python
    interpreter sessions.  This test will pass:
    ...

Let's now look at the documentation that this feature provides.

    >>> print feature.featureDocumentation
    The Automated Testing feature generates boiler plate code for running
    unittests, specifically in the form of DocTests.  Here are the various
    pieces generated by the Automated Testing Feature...
