<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Mark Morgan</title>
    <link rel="alternate" type="text/html" href="https://blogs.perl.org/users/mark_morgan/" />
    <link rel="self" type="application/atom+xml" href="https://blogs.perl.org/users/mark_morgan/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/mark_morgan//508</id>
    <updated>2010-08-30T11:19:54Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Test::Class::Filter::Tags</title>
    <link rel="alternate" type="text/html" href="https://blogs.perl.org/users/mark_morgan/2010/08/testclassfiltertags.html" />
    <id>tag:blogs.perl.org,2010:/users/mark_morgan//508.958</id>

    <published>2010-08-29T19:03:52Z</published>
    <updated>2010-08-30T11:19:54Z</updated>

    <summary>I&apos;m happy to announce the release of Test::Class::Filter::Tags. This module uses the new filter support introduced in version 0.36 of Test::Class to allow selective running of Test::Class tests. With the filter support of Test::Class, it&apos;s now possible to supply any...</summary>
    <author>
        <name>Mark Morgan</name>
        
    </author>
    
    <category term="perltestingtestclasstags" label="perl testing Test::Class tags" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="https://blogs.perl.org/users/mark_morgan/">
        <![CDATA[<p>I'm happy to announce the release of <a href="http://search.cpan.org/perldoc?Test::Class::Filter::Tags">Test::Class::Filter::Tags</a>.  This module
uses the new filter support introduced in version 0.36 of Test::Class to
allow selective running of Test::Class tests.</p>

<p>With the filter support of Test::Class, it's now possible to supply any number
of filter subs, when running Test::Class tests.  Each filter is given the
opportunity to suppress the running of each test; If any filter says to
suppress a specific test, that test will not be executed.</p>

<p>Using this mechanism, when Test::Class::Filter::Tags is used in your
Test::Class classes, you can specify 'Tags' attributes on non-fixture
(ie, not startup, setup, teardown or shutdown tests).  When running tests,
you can set an environment variable of <code>TEST_TAGS</code>, to run only the subset
of the tests that have the specified tags.  Conversely, you can limit a
subset of tests that have specified tags via the <code>TEST_TAGS_SKIP</code> environment
variable.  Both of these vars can be used to give even more granularity in
deciding what tests are run.</p>

<p>As an example of this, consider the following:  You have a large test suite,
that takes a long time to run.  When doing a bit of work, you don't want to
run the full test suite every time a change is made.  Instead, there are
some core tests that exercise your code and can run in a reasonable length
of time.  Only when looking to merge the new code back into the main branch
do you want the full test suite run.</p>

<p>When using vanilla Test::Class, the only mechanism that can support the above
behaviour is to separate the two classes of tests into multiple test classes,
and have multiple driver scripts that load only a subset of tests; Only
classes that exercise the core code for the quick subset of tests, and
a full list of classes, that execute all tests, to be run at integration or
deployment time.</p>

<p>While the above is a workable solution, it's not ideal, in that it
forces arbitrary separation of test code into disparate classes, that would
ideally be contained within a single class.  Tests that exercise the similar
functionality are now contained in multiple test classes, losing some of the
benefit of using Test::Class to group tests.</p>

<p>Using Test::Class::Filter::Tags, you can get around the above issue.  By
tagging your core developer tests, you can then choose to run just those
tests.  Simply specify the relevant tags in the <code>TEST_TAGS</code> env var when
running the tests, and only that subset will be tested, no matter where how
many test classes they're in, or whether they're interspersed with other
tests that don't have the relevant tags.  For integration, just don't specify
<code>TEST_TAGS</code>, and all tests will be run.</p>

<p>An example of this is as follows:</p>

<pre><code>package t::Foo;

use Foo;

# Get access to the 'Tags' attribute, and install the Test::Class filter.
use Test::Class::Filter::Tags;
use Test::More;

use base 'Test::Class';

sub object_creation : Test( 1 ) Tags( fast ) {
    my $foo = Foo-&gt;new( 1 );

    ok( defined $foo, "Foo lives!" );
}

sub long_slow_test : Tests( 1 ) Tags( slow ) {
    my $foo = Foo-&gt;new( "265252859812191058636308480000001" );

    is( Foo-&gt;is_prime, 1, "Finally got a result" );
}

sub non_tagged : Tests( 1 ) {
    is( 1, 1, "*sigh*" )
}

# more tests with these, or other tags
</code></pre>

<p>You can now run only the fast tests, via running your test driver script as:</p>

<pre><code>$ TEST_TAGS=fast test_driver.pl
</code></pre>

<p>This gives a result of:</p>

<pre><code>1..1
ok 1 - Foo lives!
</code></pre>

<p>Only the tests marked <code>fast</code> were run; even tests with no tags were filtered
out.  Alternatively, you may have a number of other tags, and want to run all
but the slow tests, this can again be accomplished via:</p>

<pre><code>$ TEST_TAGS_SKIP=slow test_driver.pl
1..2
ok 1 - *sigh*
ok 2 - Foo lives!
</code></pre>

<p>If you have a large Test::Class test suite that needs organising, please take
a look at this module.  I welcome any feedback about how to improve this
module, so please get in touch with me at <a href="&#109;&#x61;&#x69;&#108;t&#111;:&#x6D;&#97;&#x6B;&#x6B;&#51;&#56;&#52;&#64;&#x67;&#109;&#97;&#x69;&#108;&#46;&#x63;&#x6F;&#109;">&#x6D;&#97;&#x6B;&#x6B;&#51;&#56;&#52;&#64;&#x67;&#109;&#97;&#x69;&#108;&#46;&#x63;&#x6F;&#109;</a> if you find this
module is missing some functionality you'd desire.</p>
]]>
        

    </content>
</entry>

</feed>
