irfan rasool
irfan rasool

Reputation: 158

Auto-loading your Kohana project for unit testing in Codeception

I am very much new to Kohana and Codeception world. I was exploring how to do testing in kohana using codeception. I was able to run acceptance test. But now I want to create my Unit test for my demo app that has only sign and signup functionality.

How should I load the required files or the application instance which I will be using in the unit test.

Like I need to check if "Controller_Login" class exists. And then within this controller if "action_login" method exists or not.

I have gone through the Codeception documentation and it says that you need to auto-load your project in the unit/_bootstrap.php file. So, how should I auto-load my project. Could you please guide me.

For unit test I have written this simple test

public function testMe()
{
    $users = new User;
    $this->assertInstanceOf('User',  $users);

}

But when I run this it gives me error on console that "Class 'User' not found". How should I auto-load my project please guide me.

Upvotes: 1

Views: 402

Answers (1)

irfan rasool
irfan rasool

Reputation: 158

Writing unit test for you app using Codecpetion you need to follow these points.

  1. You need to load all your app in Codecpetion. So, that your test can easily access your classes.
  2. There is one _bootstrap.php file at the root in test folder which Codecpetion creates once you bootstrap Codecpetion. In this file you need to load your app.

For example I have done it like this to load my application folder.

define('APPPATH', realpath('application').'/');

So like this now you can create a unit test and access any class you would like to access.

Upvotes: 1

Related Questions