#!/usr/bin/perl -w use warnings; use strict; use feature qw(switch say); use Test::More tests => 3; use Test::MockObject; my $mock = Test::MockObject->new(); $mock->fake_module ('NaServer', new => sub { return 'NaServer' }, get_val => sub { return 500 }, ); use_ok( 'NaServer' ) or exit; ## includes 'use NaServer;' # Construction of $s just for testing my $s = NaServer->new( 'sim8aXXXXXX', 1, 6 ); isa_ok( $s, 'NaServer'); # ================================== # = Tests of the script start here = # ================================== use Test::Trap; use File::Slurp; my $script = 'script_to_test.pl'; my @r = trap { eval read_file($script) }; is ($trap->stdout, "Value OK (500)\n", 'stdout as expected'); __END__ # This works fine, traping after having mocked the NaServer was the trick. # Thanks to the monks!