{"id":16112343,"url":"https://github.com/pvande/test-mini-unit","last_synced_at":"2025-03-18T09:31:04.652Z","repository":{"id":1024473,"uuid":"852434","full_name":"pvande/Test-Mini-Unit","owner":"pvande","description":"Declarative Sugar for Test::Mini","archived":false,"fork":false,"pushed_at":"2011-02-13T06:12:23.000Z","size":264,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T18:42:37.714Z","etag":null,"topics":["perl","preprocessor","test-framework"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pvande.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-08-21T01:00:03.000Z","updated_at":"2014-09-08T21:12:11.000Z","dependencies_parsed_at":"2022-08-24T22:31:20.259Z","dependency_job_id":null,"html_url":"https://github.com/pvande/Test-Mini-Unit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvande%2FTest-Mini-Unit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvande%2FTest-Mini-Unit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvande%2FTest-Mini-Unit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvande%2FTest-Mini-Unit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pvande","download_url":"https://codeload.github.com/pvande/Test-Mini-Unit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244192559,"owners_count":20413547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["perl","preprocessor","test-framework"],"created_at":"2024-10-09T20:07:01.173Z","updated_at":"2025-03-18T09:31:04.285Z","avatar_url":"https://github.com/pvande.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=for comment Documentation generated by YARD v0.6.1 and yard-pod-plugin v0.1.\n\n=head1 NAME\n\nTest::Mini::Unit - Declarative Sugar for Test::Mini\n\n=head1 DESCRIPTION\n\nTest::Mini::Unit aims to provide a simpler, boilerplate-free environment\nfor writing new L\u003c\u003c\u003c\u003c S\u003c\u003c\u003c\u003c\u003c Test::Mini \u003e\u003e\u003e\u003e\u003e|Test::Mini \u003e\u003e\u003e\u003e test\ncases.  While Test::Mini itself is a fairly reasonable environment with\nvery little overhead verbosity, the overhead of creating a new class --\nor set of classes -- in Perl can still be a bit more distracting than\nyou'd really like.\n\n=head2 Enter Test::Mini::Unit\n\nAt first glance, Test::Mini::Unit provides moderate improvements over\nthe traditional style, transforming this:\n\n  package t::Test\n  use base 'Test::Mini::TestCase';\n  use strict;\n  use warnings;\n\n  use Test::Mini::Assertions;\n\n  sub setup {\n      # do something\n  }\n\n  sub test_some_code {\n      assert($something_true);\n  }\n\n  sub teardown {\n      # undo something\n  }\n\n  1;\n\nInto this:\n\n  use Test::Mini::Unit;\n\n  case t::Test {\n      setup {\n          # do something\n      }\n\n      test some_code {\n          assert($something_true);\n      }\n\n      teardown {\n          # undo something\n      }\n  }\n\n=head2 Advice\n\nBut Test::Mini::Unit really begins to shine as your test cases take on\nmore complexity.  Multiple calls to the test advice methods (C\u003c\u003c\u003c\u003c setup\n\u003e\u003e\u003e\u003e and C\u003c\u003c\u003c\u003c teardown \u003e\u003e\u003e\u003e) will stack like C\u003c\u003c\u003c\u003c BEGIN \u003e\u003e\u003e\u003e and C\u003c\u003c\u003c\u003c\nEND \u003e\u003e\u003e\u003e blocks, allowing you to co-locate tests and relevant advice.\n\n  # Traditional\n  sub setup {\n      # do a bunch of setup for test_one\n      # ...\n      # do a bunch of setup for test_two\n      # ...\n  }\n\n  sub test_one { ... }\n  sub test_two { ... }\n\n  # Test::Mini::Unit\n  setup { \"do setup for test_one\" }\n  sub test_one { ... }\n\n  setup { \"do setup for test_two\" }\n  sub test_two { ... }\n\n=head2 Test-Local Storage\n\nPer-test local storage is automatically available as C\u003c\u003c\u003c\u003c $self \u003e\u003e\u003e\u003e\nfrom all advice and test blocks.\n\n   setup { $self-\u003e{data} = Package-\u003enew() }\n   test data { assert_isa($self-\u003e{data}, 'Package') }\n\n   teardown { unlink $self-\u003e{tmpfile} }\n\n=head2 Nesting\n\nAnd perhaps most usefully, test cases can be B\u003c\u003c\u003c\u003c nested \u003e\u003e\u003e\u003e.  Nested\ntest cases inherit all their outer scope's test advice, allowing you to\nbuild richer tests with far less code.\n\n  case t::IO::Scalar {\n      setup { $self-\u003e{buffer} = IO::Scalar-\u003enew() }\n      test can_read  { assert_can($self-\u003e{buffer}, 'read')  }\n      test can_write { assert_can($self-\u003e{buffer}, 'write') }\n      test is_empty  { assert_empty(\"@{[$self-\u003e{buffer}]}\") }\n\n      case AfterWritingString {\n          setup { $self-\u003e{buffer}-\u003eprint('String!') }\n          test contents {\n              assert_equal(\"@{[$self-\u003e{buffer}]}\", 'String!');\n          }\n      }\n\n      case AfterWritingObject {\n          setup { $self-\u003e{buffer}-\u003eprint($self) }\n          test contents {\n              assert_equal(\"@{[$self-\u003e{buffer}]}\", \"$self\");\n          }\n      }\n  }\n\n=head2 Sharing Tests...\n\nIn some cases, you may find it useful to reuse the same tests in\ndifferent cases.  For this purpose, the C\u003c\u003c\u003c\u003c shared \u003e\u003e\u003e\u003e and C\u003c\u003c\u003c\u003c\nreuse \u003e\u003e\u003e\u003e keywords exist:\n\n  shared BasicBookTests {\n      test has_pages { ... }\n      test pages_have_text { ... }\n  }\n\n  case Book {\n      reuse BasicBookTests;\n  }\n\n  case LargePrintBook {\n      reuse BasicBookTests;\n      test words_should_be_big { ... }\n  }\n\n=head2 ... And Reusing Them\n\nGroups of shared tests may also be nested inside C\u003c\u003c\u003c\u003c case \u003e\u003e\u003e\u003e blocks,\nwhere they will inherit the namespace of their parent.  Since shared\ntests will most commonly see reuse inside either the C\u003c\u003c\u003c\u003c case \u003e\u003e\u003e\u003e\nthey're declared in or a nested case, it's not usually necessary to\nspecify the full package name. The C\u003c\u003c\u003c\u003c reuse \u003e\u003e\u003e\u003e keyword will try,\ntherefore, to infer the fully qualified package name from the name it's\ngiven.  (You can always specify the full name yourself by prepending\n'::'.)\n\n  shared CommonTests {\n      # __PACKAGE__ is 'Nested::CommonTests'\n  }\n\n  case Nested {\n      shared CommonTests {\n          # __PACKAGE__ is 'Nested::CommonTests'\n      }\n\n      case Deeply {\n          shared CommonTests {\n              # __PACKAGE__ is 'Nested::Deeply::CommonTests'\n          }\n\n          # includes Nested::Deeply::CommonTests\n          reuse CommonTests;\n\n          # includes Nested::CommonTests\n          reuse Nested::CommonTests;\n\n          # includes CommonTests\n          reuse ::CommonTests;\n      }\n\n      # includes Nested::CommonTests\n      reuse CommonTests;\n  }\n\n=head2 Automatic 'use'\n\nTo automatically use packages inside all your test cases (for example,\nyour own custom assertions), simply pass the 'with' option to\nTest::Mini::Unit; it can accept either a single package name or an\narray.\n\n  use Test::Mini::Unit (with =\u003e [ My::Assertions, My::HelperFuncs ]);\n\n  case t::TestCase {\n      # My::Assertions and My::HelperFuncs are already imported here.\n      case Nested {\n          # In here, too.\n      }\n\n      shared CommonTests {\n          # Yup, here too.\n      }\n  }\n\n\n\n\nSee Also:\n\n=over\n\n=item *\n\nL\u003c\u003c\u003c\u003c S\u003c\u003c\u003c\u003c\u003c Test::Mini \u003e\u003e\u003e\u003e\u003e|Test::Mini \u003e\u003e\u003e\u003e\n\n\n=back\n\n=head1 AUTHOR\n\nPieter van de Bruggen \u003cpvande@cpan.org\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvande%2Ftest-mini-unit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpvande%2Ftest-mini-unit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvande%2Ftest-mini-unit/lists"}