| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Test2::Manual::Testing 3perl" |
| 58 |
.TH Test2::Manual::Testing 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Test2::Manual::Testing \- Hub for documentation about writing tests with Test2. |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
This document outlines all the tutorials and POD that cover writing tests. This |
| 68 |
section does not cover any Test2 internals, nor does it cover how to write new |
| 69 |
tools, for that see Test2::Manual::Tooling. |
| 70 |
.SH "NAMESPACE MAP" |
| 71 |
.IX Header "NAMESPACE MAP" |
| 72 |
When writing tests there are a couple namespaces to focus on: |
| 73 |
.IP Test2::Tools::* 4 |
| 74 |
.IX Item "Test2::Tools::*" |
| 75 |
This is where toolsets can be found. A toolset exports functions that help you |
| 76 |
make assertions about your code. Toolsets will only export functions, they |
| 77 |
should not ever have extra/global effects. |
| 78 |
.IP Test2::Plugins::* 4 |
| 79 |
.IX Item "Test2::Plugins::*" |
| 80 |
This is where plugins live. Plugins should not export anything, but instead |
| 81 |
will introduce or alter behaviors for Test2 in general. These behaviors may be |
| 82 |
lexically scoped, or they may be global. |
| 83 |
.IP Test2::Bundle::* 4 |
| 84 |
.IX Item "Test2::Bundle::*" |
| 85 |
Bundles combine toolsets and plugins together to reduce your boilerplate. First |
| 86 |
time test writers are encouraged to start with the Test2::V0 bundle (which |
| 87 |
is an exception to the namespace rule as it does not live under |
| 88 |
\&\f(CW\*(C`Test2::Bundle::\*(C'\fR). If you find yourself loading several plugins and toolsets |
| 89 |
over and over again you could benefit from writing your own bundle. |
| 90 |
.IP Test2::Require::* 4 |
| 91 |
.IX Item "Test2::Require::*" |
| 92 |
This namespace contains modules that will cause a test to skip if specific |
| 93 |
conditions are not met. Use this if you have tests that only run on specific |
| 94 |
perl versions, or require external libraries that may not always be available. |
| 95 |
.SH "LISTING DEPENDENCIES" |
| 96 |
.IX Header "LISTING DEPENDENCIES" |
| 97 |
When you use Test2, specifically things included in Test2::Suite you need |
| 98 |
to list them in your modules test dependencies. It is important to note that |
| 99 |
you should list the tools/plugins/bundles you need, you should not simply list |
| 100 |
Test2::Suite as your dependency. Test2::Suite is a living distribution |
| 101 |
intended to represent the "current" best practices. As tools, plugins, and |
| 102 |
bundles evolve, old ones will become discouraged and potentially be moved from |
| 103 |
Test2::Suite into their own distributions. |
| 104 |
.PP |
| 105 |
One goal of Test2::Suite is to avoid breaking backwards compatibility. |
| 106 |
Another goal is to always improve by replacing bad designs with better ones. |
| 107 |
When necessary Test2::Suite will break old modules out into separate dists |
| 108 |
and define new ones, typically with a new bundle. In short, if we feel the need |
| 109 |
to break something we will do so by creating a new bundle, and discouraging the |
| 110 |
old one, but we will not break the old one. |
| 111 |
.PP |
| 112 |
So for example, if you use Test2::V0, and Dist::Zilla you |
| 113 |
should have this in your config: |
| 114 |
.PP |
| 115 |
.Vb 2 |
| 116 |
\& [Prereqs / TestRequires] |
| 117 |
\& Test2::V0 = 0.000060 |
| 118 |
.Ve |
| 119 |
.PP |
| 120 |
You \fBSHOULD NOT\fR do this: |
| 121 |
.PP |
| 122 |
.Vb 2 |
| 123 |
\& [Prereqs / TestRequires] |
| 124 |
\& Test2::Suite = 0.000060 |
| 125 |
.Ve |
| 126 |
.PP |
| 127 |
Because Test2::V0 might not always be part of Test2::Suite. |
| 128 |
.PP |
| 129 |
When writing new tests you should often check Test2::Suite to see what the |
| 130 |
current recommended bundle is. |
| 131 |
.PP |
| 132 |
\fIDist::Zilla\fR |
| 133 |
.IX Subsection "Dist::Zilla" |
| 134 |
.PP |
| 135 |
.Vb 2 |
| 136 |
\& [Prereqs / TestRequires] |
| 137 |
\& Test2::V0 = 0.000060 |
| 138 |
.Ve |
| 139 |
.PP |
| 140 |
\fIExtUtils::MakeMaker\fR |
| 141 |
.IX Subsection "ExtUtils::MakeMaker" |
| 142 |
.PP |
| 143 |
.Vb 7 |
| 144 |
\& my %WriteMakefileArgs = ( |
| 145 |
\& ..., |
| 146 |
\& "TEST_REQUIRES" => { |
| 147 |
\& "Test2::V0" => "0.000060" |
| 148 |
\& }, |
| 149 |
\& ... |
| 150 |
\& ); |
| 151 |
.Ve |
| 152 |
.PP |
| 153 |
\fIModule::Install\fR |
| 154 |
.IX Subsection "Module::Install" |
| 155 |
.PP |
| 156 |
.Vb 1 |
| 157 |
\& test_requires \*(AqTest2::V0\*(Aq => \*(Aq0.000060\*(Aq; |
| 158 |
.Ve |
| 159 |
.PP |
| 160 |
\fIModule::Build\fR |
| 161 |
.IX Subsection "Module::Build" |
| 162 |
.PP |
| 163 |
.Vb 7 |
| 164 |
\& my $build = Module::Build\->new( |
| 165 |
\& ..., |
| 166 |
\& test_requires => { |
| 167 |
\& "Test2::V0" => "0.000060", |
| 168 |
\& }, |
| 169 |
\& ... |
| 170 |
\& ); |
| 171 |
.Ve |
| 172 |
.SH TUTORIALS |
| 173 |
.IX Header "TUTORIALS" |
| 174 |
.SS "SIMPLE/INTRODUCTION TUTORIAL" |
| 175 |
.IX Subsection "SIMPLE/INTRODUCTION TUTORIAL" |
| 176 |
Test2::Manual::Testing::Introduction is an introduction to writing tests |
| 177 |
using the Test2 tools. |
| 178 |
.SS "MIGRATING FROM TEST::BUILDER and TEST::MORE" |
| 179 |
.IX Subsection "MIGRATING FROM TEST::BUILDER and TEST::MORE" |
| 180 |
Test2::Manual::Testing::Migrating Is a tutorial for converting old tests |
| 181 |
that use Test::Builder or Test::More to the newer Test2 way of doing |
| 182 |
things. |
| 183 |
.SS "ADVANCED PLANNING" |
| 184 |
.IX Subsection "ADVANCED PLANNING" |
| 185 |
Test2::Manual::Testing::Planning is a tutorial on the many ways to set a |
| 186 |
plan. |
| 187 |
.SS "TODO TESTS" |
| 188 |
.IX Subsection "TODO TESTS" |
| 189 |
Test2::Manual::Testing::Todo is a tutorial for markings tests as TODO. |
| 190 |
.SS SUBTESTS |
| 191 |
.IX Subsection "SUBTESTS" |
| 192 |
COMING SOON. |
| 193 |
.SS COMPARISONS |
| 194 |
.IX Subsection "COMPARISONS" |
| 195 |
COMING SOON. |
| 196 |
.PP |
| 197 |
\fISIMPLE COMPARISONS\fR |
| 198 |
.IX Subsection "SIMPLE COMPARISONS" |
| 199 |
.PP |
| 200 |
COMING SOON. |
| 201 |
.PP |
| 202 |
\fIADVANCED COMPARISONS\fR |
| 203 |
.IX Subsection "ADVANCED COMPARISONS" |
| 204 |
.PP |
| 205 |
COMING SOON. |
| 206 |
.SS "TESTING EXPORTERS" |
| 207 |
.IX Subsection "TESTING EXPORTERS" |
| 208 |
COMING SOON. |
| 209 |
.SS "TESTING CLASSES" |
| 210 |
.IX Subsection "TESTING CLASSES" |
| 211 |
COMING SOON. |
| 212 |
.SS TRAPPING |
| 213 |
.IX Subsection "TRAPPING" |
| 214 |
COMING SOON. |
| 215 |
.PP |
| 216 |
\fITRAPPING EXCEPTIONS\fR |
| 217 |
.IX Subsection "TRAPPING EXCEPTIONS" |
| 218 |
.PP |
| 219 |
COMING SOON. |
| 220 |
.PP |
| 221 |
\fITRAPPING WARNINGS\fR |
| 222 |
.IX Subsection "TRAPPING WARNINGS" |
| 223 |
.PP |
| 224 |
COMING SOON. |
| 225 |
.SS "DEFERRED TESTING" |
| 226 |
.IX Subsection "DEFERRED TESTING" |
| 227 |
COMING SOON. |
| 228 |
.SS "MANAGING ENCODINGS" |
| 229 |
.IX Subsection "MANAGING ENCODINGS" |
| 230 |
COMING SOON. |
| 231 |
.SS "AUTO-ABORT ON FAILURE" |
| 232 |
.IX Subsection "AUTO-ABORT ON FAILURE" |
| 233 |
COMING SOON. |
| 234 |
.SS "CONTROLLING RANDOM BEHAVIOR" |
| 235 |
.IX Subsection "CONTROLLING RANDOM BEHAVIOR" |
| 236 |
COMING SOON. |
| 237 |
.SS "WRITING YOUR OWN BUNDLE" |
| 238 |
.IX Subsection "WRITING YOUR OWN BUNDLE" |
| 239 |
COMING SOON. |
| 240 |
.SH "TOOLSET DOCUMENTATION" |
| 241 |
.IX Header "TOOLSET DOCUMENTATION" |
| 242 |
COMING SOON. |
| 243 |
.SH "PLUGIN DOCUMENTATION" |
| 244 |
.IX Header "PLUGIN DOCUMENTATION" |
| 245 |
COMING SOON. |
| 246 |
.SH "BUNDLE DOCUMENTATION" |
| 247 |
.IX Header "BUNDLE DOCUMENTATION" |
| 248 |
COMING SOON. |
| 249 |
.SH "REQUIRE DOCUMENTATION" |
| 250 |
.IX Header "REQUIRE DOCUMENTATION" |
| 251 |
COMING SOON. |
| 252 |
.SH "SEE ALSO" |
| 253 |
.IX Header "SEE ALSO" |
| 254 |
Test2::Manual \- Primary index of the manual. |
| 255 |
.SH SOURCE |
| 256 |
.IX Header "SOURCE" |
| 257 |
The source code repository for Test2\-Manual can be found at |
| 258 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 259 |
.SH MAINTAINERS |
| 260 |
.IX Header "MAINTAINERS" |
| 261 |
.IP "Chad Granum <[email protected]>" 4 |
| 262 |
.IX Item "Chad Granum <[email protected]>" |
| 263 |
.SH AUTHORS |
| 264 |
.IX Header "AUTHORS" |
| 265 |
.PD 0 |
| 266 |
.IP "Chad Granum <[email protected]>" 4 |
| 267 |
.IX Item "Chad Granum <[email protected]>" |
| 268 |
.PD |
| 269 |
.SH COPYRIGHT |
| 270 |
.IX Header "COPYRIGHT" |
| 271 |
Copyright 2018 Chad Granum <[email protected]>. |
| 272 |
.PP |
| 273 |
This program is free software; you can redistribute it and/or |
| 274 |
modify it under the same terms as Perl itself. |
| 275 |
.PP |
| 276 |
See \fIhttp://dev.perl.org/licenses/\fR |