What I do is that I factor out most of the code from run() in the command, 
so I can test it with normal Test::More:

  use Mojo::Base -strict;
  use Test::More;
  use MyApp::Command::foo;
  my $cmd = MyApp::Command::foo->new;
  is $cmd->get_some_stuff, 42, 'do_stuff() returned 42';
  done_testing;

You could also test run() the same way ^^^.

Note: You might want set app():

  my $cmd = MyApp::Command::foo->new;
  $cmd->app(Mojo::Server->new->build_app("MyApp"));

On Friday, July 25, 2014 4:00:43 PM UTC+2, jay m wrote:
>
>
>
> On Friday, July 25, 2014 7:34:45 AM UTC-4, sri wrote:
>>
>> The Test::Mojo doc is clear about testing the web part of a Mojo 
>>> application, but how are custom Mojo commands tested?
>>>
>>
>> Because there is nothing, proposals welcome.
>>
>>
> in real usage, commands are initiated from outside mojo (command line) and 
> the results are evaluated externally. so do we need any special features 
> for testing them beyond what Test::More provides?
>
> my $out = `$bdir/script/mojo usercount -m testing`;
> like $out,qr[users: 4/3],'total/active users loaded by fixtures';
>
> jay
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to