title: How do we unit test a Mojolicious controller?
body: <p>We have created the following simple <a href="http://mojolicio.us" rel="noreferrer">Mojolicious</a> controller:</p>
  
  <pre><code>package SampleApp::Pages;
  
  # $Id$
  
  use strict;
  use warnings;
  
  our $VERSION = '0.01';
  
  use Mojo::Base 'Mojolicious::Controller';
  
  sub home {
      my $self = shift;
  
      $self-&gt;render( 'title' =&gt; 'Home' );
  
      return;
  }
  
  sub contact {
      my $self = shift;
  
      $self-&gt;render( 'title' =&gt; 'Contact' );
  
      return;
  }
  
  sub about {
      my $self = shift;
  
      $self-&gt;render( 'title' =&gt; 'About' );
  
      return;
  }
  
  1;
  </code></pre>
  
  <p>The corresponding unit tests look as follows:</p>
  
  <pre><code>package Test::SampleApp::Pages;
  
  # $Id$
  
  use strict;
  use warnings;
  
  our $VERSION = '0.01';
  
  use Carp;
  use English '-no_match_vars';
  use Readonly;
  use Test::Mojo;
  use Test::Most;
  
  use base 'Test::Class';
  
  Readonly my $SERVER_OK =&gt; 200;
  
  sub startup : Tests(startup) {
      eval {
          require SampleApp;
  
          SampleApp-&gt;import;
  
          1;
      } or Carp::croak($EVAL_ERROR);
  
      return;
  }
  
  sub get_home : Tests(4) {
      my $test = shift;
      my $mojo = $test-&gt;mojo;
  
      $mojo-&gt;get_ok('/pages/home')-&gt;status_is($SERVER_OK);
  
      $mojo-&gt;text_is(
          'title',
          $test-&gt;base_title . ' | Home',
          '... and should have the right title'
      );
  
      $mojo-&gt;content_like(
          qr/&lt;body&gt;(?:\s*\S+\s*)+&lt;\/body&gt;/msx,
          '... and should have a non-blank body'
      );
  
      return;
  }
  
  sub get_contact : Tests(3) {
      my $test = shift;
      my $mojo = $test-&gt;mojo;
  
      $mojo-&gt;get_ok('/pages/contact')-&gt;status_is($SERVER_OK);
  
      $mojo-&gt;text_is(
          'title',
          $test-&gt;base_title . ' | Contact',
          '... and should have the right title'
      );
  
      return;
  }
  
  sub get_about : Tests(3) {
      my $test = shift;
      my $mojo = $test-&gt;mojo;
  
      $mojo-&gt;get_ok('/pages/about')-&gt;status_is($SERVER_OK);
  
      $mojo-&gt;text_is(
          'title',
          $test-&gt;base_title . ' | About',
          '... and should have the right title'
      );
  
      return;
  }
  
  sub base_title {
      my ( $self, $base_title ) = @_;
  
      if ( defined $base_title ) {
          $self-&gt;{base_title} = $base_title;
      }
  
      return $self-&gt;{base_title};
  }
  
  sub mojo {
      my ( $self, $mojo ) = @_;
  
      if ( defined $mojo ) {
          $self-&gt;{mojo} = $mojo;
      }
  
      return $self-&gt;{mojo};
  }
  
  sub setup : Tests(setup) {
      my $test = shift;
  
      $test-&gt;base_title('Mojolicious Sample App');
  
      $test-&gt;mojo( Test::Mojo-&gt;new( app =&gt; 'SampleApp', max_redirects =&gt; 1 ) );
  
      return;
  }
  
  1;
  </code></pre>
  
  <p>To us, this is more like functionality testing rather than unit testing</p>
  
  <p>Is there a way to call the <code>home</code> method of the controller and test its output that doesn't require starting up a server instance via <code>Test::Mojo</code>?</p>