Problems running tests in a RT extension

Hi,

I’m writing a extension for RT 4.4 and I am struggling with getting the unit tests to run properly.

My test file xt/basic.t contains the following:

  use strict;
  use warnings;

  use RT::Extension::CSVCustomFields::Test tests => undef;

  use_ok('RT::Extension::CSVCustomFields');
  use_ok('RT::CustomField');

  # Load the General Queue
  my $queue = RT::Test->load_or_create_queue( Name => 'General' );
  ok( $queue->id, "loaded the General queue" );

  # Create a new customfield
  my $cf = RT::CustomField->new(RT->SystemUser);
  ok( $cf->Create( Name => 'testcsv', Queue => $queue->id, Type => 'Freeform' ) );

  my ($baseurl, $agent) = RT::Test->started_ok;

  done_testing;

I’m running the tests as follows and get the following output:

$ perl -Ilib xt/basic.t

ok 1 - There is no etc dir: no schema
ok 2 - There is no etc dir: no ACLs
ok 3 - There is no etc dir: no data
ok 4 - use RT::Extension::CSVCustomFields;
ok 5 - use RT::CustomField;
ok 6 - loaded the General queue
ok 7
# did not get expected USR1 for test server readiness
ok 8 - started plack server ok
Can't locate object method "new" via package "RT::Test::Web" at /home/wheldonm/rt4-test-modules/lib/RT/Test/Web.pm line 68.
Can't locate object method "new" via package "RT::Test::Web" at /home/wheldonm/rt4-test-modules/lib/RT/Test/Web.pm line 68.
not ok 9 - no warnings
#   Failed test 'no warnings'
#   at /home/wheldonm/rt4-test-modules/lib/RT/Test.pm line 1783.
# There were 1 warning(s)
#       Previous test 8 'started plack server ok'
#       Can't locate object method "new" via package "RT::Test::Web" at /home/wheldonm/rt4-test-modules/lib/RT/Test/Web.pm line 68.
#  at /home/wheldonm/.perlbrew/libs/current@martin/lib/perl5/Log/Dispatch/Perl.pm line 84.

I’ve also tried invoking using the following, but with similar results:

$ prove -l lib -v xt

It feels like I’m not invoking the tests correctly, but I’ve not found any documentation telling me how to.
Sorry about the long post. Any help would be much appreciated.

Martin

Hi,

Seems that I was invoking the tests incorrectly, I should read the
instructions more closely.
I hadn’t set the RTHOME variable :frowning:

So for anyone with the same issue in the future:

cd rt-extension-csvcustomfields
export RTHOME=/opt/mytestrtinstance; prove -l lib -v xt

Sorry for the noise

Martin

1 Like

One other thing to add right before the done_testing call is:

undef $agent;

That will clean up the test web object and avoid additional warnings that will show up as test failures.

1 Like