<p>Are there conventions for function names when using the Perl Test::More or Test::Simple modules?</p>

<p>I'm specifically asking about the names of functions that are used to set up a test environment before the test and to tear down the environment after successful completion of the test(s).</p>

<p>cheers,</p>

<p>Rob</p>

[{'answer_id': 45491, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 1, 'selected': False, 'text': '<p>I do not think there is a official set of conventions, so I would recommend looking at the examples at <a href="http://perldoc.perl.org/Test/More.html" rel="nofollow noreferrer">http://perldoc.perl.org/Test/More.html</a> and see how the write their tests.</p>\n'}, {'answer_id': 45504, 'author': 'Rob Wells', 'author_id': 2974, 'author_profile': 'https://Stackoverflow.com/users/2974', 'pm_score': 1, 'selected': False, 'text': "<p>Thanks Espo.</p>\n\n<p>I've had a look at the relevant perldocs but there's no real convention regarding the setup and teardown aspects.</p>\n\n<p>Not like XUnit series of tests.</p>\n\n<p>Thanks for the answer Jagmal but I'm not sure about using the BEGIN and END blocks for the setup and teardown as you are not making clear what you are doing by the names. There's also the obvious problem of only having one setup run and one teardown run per test, i.e. per each .t file.</p>\n\n<p>I've had a quick look at Test::Most and it looks really interesting, especially the explain function. Thanks Matt.</p>\n\n<p>Hmmm. Just thinking further about using the BEGIN and END blocks, I'm thinking if I decrease the granularity of the tests so that there is only one setup and one teardown needed then this would be a good solution.</p>\n\n<p>cheers,</p>\n\n<p>Rob</p>\n"}, {'answer_id': 45542, 'author': 'Jagmal', 'author_id': 4406, 'author_profile': 'https://Stackoverflow.com/users/4406', 'pm_score': 3, 'selected': True, 'text': '<p>I dont think there are any such conventions out there.</p>\n\n<p>The only way you can do it is perhaps use BEGIN/END blocks, if the resources are to be used over the whole file.</p>\n\n<p>The general approach I take is to put related tests in one code block and then initialize the variables/resource etc there. You can perhaps keep an easy count of how many tests you have for each function.</p>\n\n<p>Something like ...</p>\n\n<pre><code>BEGIN {\n   # If you want to set some global db setting/file setting/INC changes etc\n}\n\n# Tests functionality 1...\n{\n     # have fun .... \n}\n\n# Tests functionality 2...\n{\n     # have more fun .... \n}\n\nEND {\n   # Clean up the BEGIN changes\n}\n</code></pre>\n\n<p>On other note, you may want to read this for testing in perl ... <a href="http://perlandmac.blogspot.com/2007/08/using-perl-testsimple-and-testmore.html" rel="nofollow noreferrer">http://perlandmac.blogspot.com/2007/08/using-perl-testsimple-and-testmore.html</a></p>\n'}, {'answer_id': 45672, 'author': 'dagorym', 'author_id': 171, 'author_profile': 'https://Stackoverflow.com/users/171', 'pm_score': 1, 'selected': False, 'text': "<p>We use Test::More extensively for our unit tests as a lot (most) of our data processing scripts are written in Perl.  We don't have a specific convention for the function names but rather do something like Jagmal suggests, namely breaking the tests up into smaller chunks and initializing locally.</p>\n\n<p>In our case each subtest is encapsulated in a separate function within the test script.  On top of this we have a framework that allows us to run all the subtests (the full unit test) or call individual subtests or sets of subtests to allow for running of just the ones we're working on at the moment.</p>\n"}, {'answer_id': 45674, 'author': 'Matthew Watson', 'author_id': 3839, 'author_profile': 'https://Stackoverflow.com/users/3839', 'pm_score': 0, 'selected': False, 'text': "<p>First convention I'd suggest is ditching Test::More for Test::Most</p>\n"}, {'answer_id': 70902, 'author': 'mdxi', 'author_id': 11164, 'author_profile': 'https://Stackoverflow.com/users/11164', 'pm_score': 0, 'selected': False, 'text': "<p>Perl testing scripts aren't special or magic in any way. As such, they can contain the exact same things that any other Perl script can.</p>\n\n<p>You can name routines anything you want, and call them before, after, and intertwingled with, your tests.</p>\n\n<p>You can have any amount of initialization code before any tests, any amount of cleanup code after tests, and any amount of any other code mixed in with tests.</p>\n\n<p>This all assumes that you're talking about CPAN-style t/*.t test scripts. I think you are, but I can manage to read your question as one about extending test harnesses, if I squint just right. </p>\n"}, {'answer_id': 70912, 'author': 'Aristotle Pagaltzis', 'author_id': 9410, 'author_profile': 'https://Stackoverflow.com/users/9410', 'pm_score': 2, 'selected': False, 'text': '<p>If you are looking for more XUnit-style testing, check out <a href="http://search.cpan.org/perldoc?Test::Class" rel="nofollow noreferrer">Test::Class</a>. It provides the <code>Test(setup)</code> and <code>Test(teardown)</code> attributes for methods that, well, set up and tear down your environment. It also gives you a much nicer way of dealing with plans (you can provide one for each test method individually, so the counting is much less fiddly) and lets you inherit tests via test class hierarchies.</p>\n'}, {'answer_id': 642458, 'author': 'Evgeny', 'author_id': 11414, 'author_profile': 'https://Stackoverflow.com/users/11414', 'pm_score': 0, 'selected': False, 'text': '<p>If you are open to get into acceptance testing as well, like Ruby\'s Cucumber - take a look at this small example <a href="http://github.com/kesor/p5-cucumber" rel="nofollow noreferrer">http://github.com/kesor/p5-cucumber</a> that is using Test::More and a cucumber style of acceptance testing.</p>\n'}]
['https://Stackoverflow.com/questions/45485', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2974/']