{
    "content": [
        {
            "type": "text",
            "text": "# Test::Unit::TestCase (perldoc)\n\n## NAME\n\nTest::Unit::TestCase - unit testing framework base class\n\n## SYNOPSIS\n\npackage FooBar;\nuse base qw(Test::Unit::TestCase);\nsub new {\nmy $self = shift()->SUPER::new(@);\n# your state for fixture here\nreturn $self;\n}\nsub setup {\n# provide fixture\n}\nsub teardown {\n# clean up after test\n}\nsub testfoo {\nmy $self = shift;\nmy $obj = ClassUnderTest->new(...);\n$self->assertnotnull($obj);\n$self->assertequals('expected result', $obj->foo);\n$self->assert(qr/pattern/, $obj->foobar);\n}\nsub testbar {\n# test the bar feature\n}\n\n## DESCRIPTION\n\nTest::Unit::TestCase is the 'workhorse' of the PerlUnit framework. When writing tests, you\ngenerally subclass Test::Unit::TestCase, write \"setup\" and \"teardown\" functions if you need\nthem, a bunch of \"test*\" test methods, then do\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (4 subsections)\n- **NOTES**\n- **BUGS**\n- **AUTHOR**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Test::Unit::TestCase",
        "section": "",
        "mode": "perldoc",
        "summary": "Test::Unit::TestCase - unit testing framework base class",
        "synopsis": "package FooBar;\nuse base qw(Test::Unit::TestCase);\nsub new {\nmy $self = shift()->SUPER::new(@);\n# your state for fixture here\nreturn $self;\n}\nsub setup {\n# provide fixture\n}\nsub teardown {\n# clean up after test\n}\nsub testfoo {\nmy $self = shift;\nmy $obj = ClassUnderTest->new(...);\n$self->assertnotnull($obj);\n$self->assertequals('expected result', $obj->foo);\n$self->assert(qr/pattern/, $obj->foobar);\n}\nsub testbar {\n# test the bar feature\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 13,
                "subsections": [
                    {
                        "name": "How To Use Test::Unit::TestCase",
                        "lines": 54
                    },
                    {
                        "name": "Writing Test Methods",
                        "lines": 21
                    },
                    {
                        "name": "Helper methods",
                        "lines": 22
                    },
                    {
                        "name": "How it All Works",
                        "lines": 13
                    }
                ]
            },
            {
                "name": "NOTES",
                "lines": 46,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 12,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Test::Unit::TestCase - unit testing framework base class\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "package FooBar;\nuse base qw(Test::Unit::TestCase);\n\nsub new {\nmy $self = shift()->SUPER::new(@);\n# your state for fixture here\nreturn $self;\n}\n\nsub setup {\n# provide fixture\n}\nsub teardown {\n# clean up after test\n}\nsub testfoo {\nmy $self = shift;\nmy $obj = ClassUnderTest->new(...);\n$self->assertnotnull($obj);\n$self->assertequals('expected result', $obj->foo);\n$self->assert(qr/pattern/, $obj->foobar);\n}\nsub testbar {\n# test the bar feature\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Test::Unit::TestCase is the 'workhorse' of the PerlUnit framework. When writing tests, you\ngenerally subclass Test::Unit::TestCase, write \"setup\" and \"teardown\" functions if you need\nthem, a bunch of \"test*\" test methods, then do\n\n$ TestRunner.pl My::TestCase::Class\n\nand watch as your tests fail/succeed one after another. Or, if you want your tests to work under\nTest::Harness and the standard perlish 'make test', you'd write a t/foo.t that looked like:\n\nuse Test::Unit::HarnessUnit;\nmy $r = Test::Unit::HarnessUnit->new();\n$r->start('My::TestCase::Class');\n",
                "subsections": [
                    {
                        "name": "How To Use Test::Unit::TestCase",
                        "content": "(Taken from the JUnit TestCase class documentation)\n\nA test case defines the \"fixture\" (resources need for testing) to run multiple tests. To define\na test case:\n\n1   implement a subclass of TestCase\n\n2   define instance variables that store the state of the fixture (I suppose if you are using\nClass::MethodMaker this is possible...)\n\n3   initialize the fixture state by overriding \"setup()\"\n\n4   clean-up after a test by overriding \"teardown()\".\n\nImplement your tests as methods. By default, all methods that match the regex \"/^test/\" are\ntaken to be test methods (see \"listtests()\" and \"getmatchingmethods()\"). Note that, by\ndefault all the tests defined in the current class and all of its parent classes will be run. To\nchange this behaviour, see \"NOTES\".\n\nBy default, each test runs in its own fixture so there can be no side effects among test runs.\nHere is an example:\n\npackage MathTest;\nuse base qw(Test::Unit::TestCase);\n\nsub new {\nmy $self = shift()->SUPER::new(@);\n$self->{value1} = 0;\n$self->{value2} = 0;\nreturn $self;\n}\n\nsub setup {\nmy $self = shift;\n$self->{value1} = 2;\n$self->{value2} = 3;\n}\n\nFor each test implement a method which interacts with the fixture. Verify the expected results\nwith assertions specified by calling \"$self->assert()\" with a boolean value.\n\nsub testadd {\nmy $self = shift;\nmy $result = $self->{value1} + $self->{value2};\n$self->assert($result == 5);\n}\n\nOnce the methods are defined you can run them. The normal way to do this uses reflection to\nimplement \"runtest\". It dynamically finds and invokes a method. For this the name of the test\ncase has to correspond to the test method to be run. The tests to be run can be collected into a\nTestSuite. The framework provides different test runners, which can run a test suite and collect\nthe results. A test runner either expects a method \"suite()\" as the entry point to get a test to\nrun or it will extract the suite automatically.\n"
                    },
                    {
                        "name": "Writing Test Methods",
                        "content": "The return value of your test method is completely irrelevant. The various test runners assume\nthat a test is executed successfully if no exceptions are thrown. Generally, you will not have\nto deal directly with exceptions, but will write tests that look something like:\n\nsub testsomething {\nmy $self = shift;\n# Execute some code which gives some results.\n...\n# Make assertions about those results\n$self->assertequals('expected value', $resultA);\n$self->assertnotnull($resultobject);\n$self->assert(qr/somepattern/, $resultB);\n}\n\nThe assert methods throw appropriate exceptions when the assertions fail, which will generally\nstringify nicely to give you sensible error reports.\n\nTest::Unit::Assert has more details on the various different \"assert\" methods.\n\nTest::Unit::Exception describes the Exceptions used within the \"Test::Unit::*\" framework.\n"
                    },
                    {
                        "name": "Helper methods",
                        "content": "maketestfromcoderef (CODEREF, [NAME])\nTakes a coderef and an optional name and returns a Test case that inherits from the object\non which it was called, which has the coderef installed as its \"runtest\" method.\nClass::Inner has more details on how this is generated.\n\nlisttests\nReturns the list of test methods in this class and its parents. You can override this in\nyour own classes, but remember to call \"SUPER::listtests\" in there too. Uses\n\"getmatchingmethods\".\n\ngetmatchingmethods (REGEXP)\nReturns the list of methods in this class matching REGEXP.\n\nsetup\nteardown\nIf you don't have any setup or tear down code that needs to be run, we provide a couple of\nnull methods. Override them if you need to.\n\nannotate (MESSAGE)\nYou can accumulate helpful debugging for each testcase method via this method, and it will\nonly be outputted if the test fails or encounters an error.\n"
                    },
                    {
                        "name": "How it All Works",
                        "content": "The PerlUnit framework is achingly complex. The basic idea is that you get to write your tests\nindependently of the manner in which they will be run, either via a \"make test\" type script, or\nthrough one of the provided TestRunners, the framework will handle all that for you. And it\ndoes. So for the purposes of someone writing tests, in the majority of cases the answer is 'It\njust does.'.\n\nOf course, if you're trying to extend the framework, life gets a little more tricky. The core\nclass that you should try and grok is probably Test::Unit::Result, which, in tandem with\nwhichever TestRunner is being used mediates the process of running tests, stashes the results\nand generally sits at the centre of everything.\n\nBetter docs will be forthcoming.\n"
                    }
                ]
            },
            "NOTES": {
                "content": "Here's a few things to remember when you're writing your test suite:\n\nTests are run in 'random' order; the list of tests in your TestCase are generated automagically\nfrom its symbol table, which is a hash, so methods aren't sorted there.\n\nIf you need to specify the test order, you can do one of the following:\n\n*   Set @TESTS\n\nour @TESTS = qw(mytest mytest2);\n\nThis is the simplest, and recommended way.\n\n*   Override the \"listtests()\" method\n\nto return an ordered list of methodnames\n\n*   Provide a \"suite()\" method\n\nwhich returns a Test::Unit::TestSuite.\n\nHowever, even if you do manage to specify the test order, be careful, object data will not be\nretained from one test to another, if you want to use persistent data you'll have to use package\nlexicals or globals. (Yes, this is probably a bug).\n\nIf you only need to restrict which tests are run, there is a filtering mechanism available.\nOverride the \"filter()\" method in your testcase class to return a hashref whose keys are filter\ntokens and whose values are either arrayrefs of test method names or coderefs which take the\nmethod name as the sole parameter and return true if and only if it should be filtered, e.g.\n\nsub filter {{\nslow => [ qw(myslowtest myreallyslowtest) ],\nmatchingfoo => sub {\nmy $method = shift;\nreturn $method =~ /foo/;\n}\n}}\n\nThen, set the filter state in your runner before the test run starts:\n\n# @filtertokens = ( 'slow', ... );\n$runner->filter(@filtertokens);\n$runner->start(@args);\n\nThis interface is public, but currently undocumented (see doc/TODO).\n",
                "subsections": []
            },
            "BUGS": {
                "content": "See note 1 for at least one bug that's got me scratching my head. There's bound to be others.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Copyright (c) 2000-2002, 2005 the PerlUnit Development Team (see Test::Unit or the AUTHORS file\nincluded in this distribution).\n\nAll rights reserved. This program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "*   Test::Unit::Assert\n\n*   Test::Unit::Exception\n\n*   Test::Unit::TestSuite\n\n*   Test::Unit::TestRunner\n\n*   Test::Unit::TkTestRunner\n\n*   For further examples, take a look at the framework self test collection (t::tlib::AllTests).\n",
                "subsections": []
            }
        }
    }
}