1

Just a quick question which I couldn't Google : is class autoloading not "enabled" when running tests using SimpleTest?

I'm using the Drupal SimpleTest module, and I'm trying to instantiate a class which I have defined in files[] (in the .info) file. However, I just keep getting a message saying that the class could not be found.

2 Answers 2

1

I assumed that all "autoloadable" files for the module I was testing would indeed be automatically loaded, but this seemed to be wrong.

I needed to add the following function to my testclass:

public function setUp() {
  parent::setUp('mta');
}

Please note that 'mta' is the module I'm testing, and which the "autoloadable" classes are defined for. I assume that if you need access to "autoloadable" classes defined for any other module, that you need to set up those modules too.

1
  • This is not working for me. Apr 20, 2016 at 15:25
0

It should also be noted that unit tests and web tests behave differently. Unit tests tend to not have class loading set up.

1
  • So how do I get autoloading in unit tests?
    – donquixote
    Jul 20, 2016 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.