=head1 NAME
-Catalyst::Manual::Tutorial::Testing - Catalyst Tutorial - Part 7: Testing
+Catalyst::Manual::Tutorial::Testing - Catalyst Tutorial - Part 8: Testing
=head1 OVERVIEW
-This is B<Part 7 of 9> for the Catalyst tutorial.
+This is B<Part 8 of 10> for the Catalyst tutorial.
L<Tutorial Overview|Catalyst::Manual::Tutorial>
=item 3
-L<Basic CRUD|Catalyst::Manual::Tutorial_BasicCRUD>
+L<More Catalyst Basics|Catalyst::Manual::Tutorial::MoreCatalystBasics>
=item 4
-L<Authentication|Catalyst::Manual::Tutorial::Authentication>
+L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>
=item 5
-L<Authorization|Catalyst::Manual::Tutorial::Authorization>
+L<Authentication|Catalyst::Manual::Tutorial::Authentication>
=item 6
-L<Debugging|Catalyst::Manual::Tutorial::Debugging>
+L<Authorization|Catalyst::Manual::Tutorial::Authorization>
=item 7
-B<Testing>
+L<Debugging|Catalyst::Manual::Tutorial::Debugging>
=item 8
-L<AdvancedCRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
+B<Testing>
=item 9
+L<Advanced CRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
+
+=item 10
+
L<Appendices|Catalyst::Manual::Tutorial::Appendices>
=back
+
=head1 DESCRIPTION
You may have noticed that the Catalyst Helper scripts automatically
You can checkout the source code for this example from the catalyst
subversion repository as per the instructions in
-L<Catalyst::Manual::Tutorial::Intro>
+L<Catalyst::Manual::Tutorial::Intro|Catalyst::Manual::Tutorial::Intro>.
+
=head1 RUNNING THE "CANNED" CATALYST TESTS
$ prove --lib lib t
-The redirection used by the Authentication plugins will cause the
-default C<t/01app.t> to fail. You can fix this by changing the line in
-C<t/01app.t> that read:
+There will be a lot of output because we have the C<-Debug> flag
+enabled in C<lib/MyApp.pm> (see the C<CATALYST_DEBUG=0> tip below for
+a quick and easy way to reduce the clutter). Look for lines like this
+for errors:
+
+ # Failed test 'Request should succeed'
+ # in t/controller_Books.t at line 8.
+ # Looks like you failed 1 test of 3.
+
+The redirection used by the Authentication plugins will cause several
+failures in the default tests. You can fix this by making the following
+changes:
+
+1) Change the line in C<t/01app.t> that read:
ok( request('/')->is_success, 'Request should succeed' );
ok( request('/login')->is_success, 'Request should succeed' );
-So that a redirect is not necessary. Also, the C<t/controller_Books.t>
-and C<t/controller_Logout.t> default test cases will fail because of the
-authorization. You can delete these two files to prevent false error
-messages:
+2) Change the "C<request('/logout')-E<gt>is_success>" to
+"C<request('/logout')-E<gt>is_redirect>" in C<t/controller_Logout.t>.
+
+3) Change the "C<request('/books')-E<gt>is_success>" to
+"C<request('/books')-E<gt>is_redirect>" in C<t/controller_Books.t>.
- $ rm t/controller_Books.t
- $ rm t/controller_Logout.t
+4) Add "C<use MyApp;>" to the top of C<t/view_TT.t>.
As you can see in the C<prove> command line above, the C<--lib> option
is used to set the location of the Catalyst C<lib> directory. With this
$ CATALYST_DEBUG=0 prove --lib lib t
+B<Note:> Depending on the versions of various modules you have
+installed, you might get some C<used only once> warnings -- you can
+ignore these. If you are following along in Ubuntu 8.10, you can
+prevent them by adding C<no warnings;> above line 49 in
+C</usr/lib/perl5/Template/Base.pm> to match the following:
+
+ ...
+ { no strict qw( refs );
+ no warnings;
+ $argnames = \@{"$class\::BASEARGS"} || [ ];
+ }
+ ...
+
During the C<t/02pod> and C<t/03podcoverage> tests, you might notice the
C<all skipped: set TEST_POD to enable this test> warning message. To
execute the Pod-related tests, add C<TEST_POD=1> to the C<prove>
$ CATALYST_DEBUG=0 TEST_POD=1 prove --lib lib -v t
+
=head1 RUNNING A SINGLE TEST
You can also run a single script by appending its name to the C<prove>
$ CATALYST_DEBUG=0 prove --lib lib t/01app.t
-Note that you can also run tests directly from Perl without C<prove>.
+Also note that you can also run tests directly from Perl without C<prove>.
For example:
$ CATALYST_DEBUG=0 perl -Ilib t/01app.t
+
=head1 ADDING YOUR OWN TEST SCRIPT
Although the Catalyst helper scripts provide a basic level of checks
"Check we ARE logged in" ) for $ua1, $ua2;
# 'Click' the 'Logout' link (see also 'text_regex' and 'url_regex' options)
- $_->follow_link_ok({n => 1}, "Logout via first link on page") for $ua1, $ua2;
+ $_->follow_link_ok({n => 4}, "Logout via first link on page") for $ua1, $ua2;
$_->title_is("Login", "Check for login title") for $ua1, $ua2;
$_->content_contains("You need to log in to use this application",
"Check we are NOT logged in") for $ua1, $ua2;
$_->content_contains("Book List", "Check for book list title") for $ua1, $ua2;
# Make sure the appropriate logout buttons are displayed
- $_->content_contains("/logout\">Logout</a>",
+ $_->content_contains("/logout\">User Logout</a>",
"Both users should have a 'User Logout'") for $ua1, $ua2;
$ua1->content_contains("/books/form_create\">Create</a>",
"Only 'test01' should have a create link");
Experiment with the C<DBIC_TRACE>, C<CATALYST_DEBUG>
and C<-v> settings. If you find that there are errors, use the
-techniques discussed in the "Catalyst Debugging" section (Part 6) to
+techniques discussed in the "Catalyst Debugging" section (Part 7) to
isolate and fix any problems.
If you want to run the test case under the Perl interactive debugger,
temporarily insert a line similar to the following right after the
failed test:
- warn $ua1->content;
+ diag $ua1->content;
This will cause the full HTML returned by the request to be displayed.
+Another approach to see the full HTML content at the failure point in
+a series of tests would be to insert a "C<$DB::single=1;> right above
+the location of the failure and run the test under the perl debugger
+(with C<-d>) as shown above. Then you can use the debugger to explore
+the state of the application right before or after the failure.
+
=head1 SUPPORTING BOTH PRODUCTION AND TEST DATABASES
it runs your full application; however, this can complicate things when
you want to support multiple databases. One solution is to allow the
database specification to be overridden with an environment variable.
-For example, open C<lib/MyApp/Model/MyAppDB.pm> in your editor and
+For example, open C<lib/MyApp/Model/DB.pm> in your editor and
change the C<__PACKAGE__-E<gt>config(...> declaration to resemble:
my $dsn = $ENV{MYAPP_DSN} ||= 'dbi:SQLite:myapp.db';
__PACKAGE__->config(
- schema_class => 'MyAppDB',
+ schema_class => 'MyApp::Schema',
connect_info => [
$dsn,
- '',
- '',
- { AutoCommit => 1 },
-
],
);
Please report any errors, issues or suggestions to the author. The
most recent version of the Catalyst Tutorial can be found at
-L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Runtime/lib/Catalyst/Manual/Tutorial/>.
+L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/>.
-Copyright 2006, Kennedy Clark, under Creative Commons License
-(L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).
+Copyright 2006-2008, Kennedy Clark, under Creative Commons License
+(L<http://creativecommons.org/licenses/by-sa/3.0/us/>).