Walkthrough Testing

This wiki entry will explore the walkthrough tests and how they work and best practices for writing them.  This wiki entry is a work in progress.

Best Practice Items:

  • Watch out for caching issues. Walkthrough tests tend to switch users, and call up sequentially a lot of methods that would not normally be called up. You need to make sure you clear the cache on models when appropriate.  Sometimes this means you should call forget like:
    $model->forget()
  • When you want to switch the current user during a test, it is best to use the following:
    $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

    instead of:

    Yii::app()->user->userModel = $super

    as this will help ensure the caches is properly refreshed.
    Do note that this must be done for tests that make use of runController. For other methods(such as setUpBeforeClass) where runController is not involved it is not mandatory.



				

Leave a Comment