Testing Wishes
- Have the Phing produce test stubs for Models / Actions / Views
- Would be cool if we could parse code to check for missing tests for methods
- Mock Objects
- Allow for functional testing
Mocks
- Easy mocking for testing in isolation as well as with dependencies
- i.e. $model = $test->addMockModel('ProductModel');
- Make it easy to do - Agavi specific if needs be so users use it
Rails / Django Functional Test examples
- Rails:
def test_GET_index_returns_200_OK get :index assert_template "generator/index" assert_response :success assert_equal assigns(:campaigns).length, 14 end def test_POST_index_saves_army_in_session_and_redirects post :index, :army => {:id => 1} assert_equal 1, get_session_variable(:army).id assert_redirected_to(:action => "number_of_units") end
- Django:
def test_GET_index_returns_200_OK(self): response = self.client.get("/generator/index/") self.failUnlessEqual(response.status_code, 200) self.failUnlessEqual(response.template.name, "generator/index.html") self.failUnlessEqual(len(response.context["campaigns"]), 14) def test_POST_index_saves_army_in_session_and_redirects(self): response = self.client.post("/generator/index", {"army" : 1}) self.failUnlessEqual(response.status_code, 302) self.failUnlessEqual(response.headers["Location"], "/generator/number_of_units/" ) self.assertEqual(self.client.session["army"].id, 1)
Ross-Testing Branch
Tests generated automatically via phing via the ./agavi batch / shell script
Currently to run tests you use phing directly in the tests directory.
Tests Options
- test - run a selection of tests - (i.e. all functional tests for the Default Module)
- test-single - run a single test
- test-report - run all tests and generate html report
Tests Directory Structure
Agavi App Root
|- app
|- dev
|- pub
|_ tests
|- build.xml - phing file to run your tests
|- app
| |- libs - tests for any extended core libs - i.e. ./user/BaseRBACSecurityUserTest.php
| | |- functional tests
| | | |_ ..
| | |_ unit
| | |_ ..
| |- models - top level models
| | |- functional tests
| | | |_ ..
| | |_ unit
| | |_ ..
| |_ modules
| |_ Module Name
| |- functional
| | |- actions
| |_ unit
| |- actions
| |- models
| |_ views
|_ configs
| |_ config.php
|
|_ libs - Agavi Test Classes
|- AgaviTest.php
|- AgaviBrowser.class.php
|_ AgaviTestCase.class.php

