someone help me about functional testing

I have a very simple function test like this:

class AuthTest extends CWebTestCase{


	public function testLogin(){






when run as phpunit functional:

wfooxd@wfooxd-vb:~/www/sgserver/protected/tests$ phpunit functional/AuthTest.php 

PHPUnit @package_version@ by Sebastian Bergmann.

Configuration read from /home/wfooxd/www/sgserver/protected/tests/phpunit.xml


Time: 0 seconds, Memory: 8.25Mb

There was 1 error:

1) AuthTest::testLogin

Current URL: OR Server Exception: sessionId should not be null; has this session been started yet?

setBrowserUrl() needs to be called before start().



Tests: 1, Assertions: 0, Errors: 1.

I don’t understand why?

That’s a hint.

setBrowserUrl is (in yii) by default called in WebTestCase (protected/tests) and your test case should extend WebTestCase, not CWebTestCase.

If you don’t feel like having some common settings in WebTestCase, you can call setBrowserUrl in setUp() function in each test case, but that will lead to copy-paste kind of code reusability which is not good.

You probably didn’t set TEST_BASE_URL, so your WebTestCase.php file should look like:



class WebTestCase extends CWebTestCase



	 * Sets up before each test method runs.

	 * This mainly sets the base URL for the test application.


	protected function setUp()







and then our function test case need to extend WebTestCase.

Hope this will help.