0

I have setup a file called mymodule.test and in the module I have file called mymodule.inc. Every is working but I am unsure about the following. Below is mymodule.test file.

class MyModule extends DrupalWebTestCase {

  public static function getInfo() {
    return array (
      'name' => t('my module'),
      'description' => t('my module.'),
      'group' => t('My module'),
    );
  }
  public function setUp() {
    parent::setUp('mymodule');
  }
}

Inside mymodule.inc I have the following function

function mydisplay(){ returns "This is true" }

How I do I tell tests class I want to do an test assertion of true or false on the mydisplay function?

1

You need to add a method whose names start with test, for example testMyDisplay(), where you test the value returned from the function.

public testMyDisplay() {
  module_load_include('inc', 'mymodule');
  $this->assertEqual($expected_result, mydisplay());
}

Clearly, this code is valid if the function is not a form builder; otherwise, the code needs to be different. Since you used DrupalWebTestCase as base class, and not DrupalTestCase, I guess you need to do more than just checking the result returned from a function, or that function is not simply a function that returns a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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