SimpleTest conversion: Difference between revisions
From MoodleDocs
No edit summary |
|||
Line 21: | Line 21: | ||
! Notes | ! Notes | ||
|- | |- | ||
| $this->assertEqual($expected, $actual) | | <code php>$this->assertEqual($expected, $actual)</code> | ||
| $this->assertEquals($expected, $actual) | | <code php>$this->assertEquals($expected, $actual)</code> | ||
| | | | ||
|- | |- | ||
| $this->assertIdentical($expected, $actual) | | <code php>$this->assertIdentical($expected, $actual)</code> | ||
| $this->assertSame($expected, $actual) | | <code php>$this->assertSame($expected, $actual)</code> | ||
| | | | ||
|- | |- | ||
| $this->assertTrue($actual) | | <code php>$this->assertTrue($actual)</code> | ||
| $this->assertTrue((bool)$a, $b) | | <code php>$this->assertTrue((bool)$a, $b)</code> | ||
| SimpleTest convers parameter to bool. | | SimpleTest convers parameter to bool. | ||
|- | |||
| <code php>$this->assertFalse($actual)</code> | |||
| <code php>$this->assertFalse((bool)$a, $b)</code> | |||
| SimpleTest convers parameter to bool. | |||
|- | |||
| <code php>$this->expectException(true)</code> | |||
| <code php>$this->setExpectedException('exception_name')</code> | |||
| | |||
|- | |||
| <code php>$this->expectError()</code> | |||
| <code php>$this->setExpectedException('PHPUnit_Framework_Error')</code> | |||
| | |||
|} | |} | ||
[[Category:Unit testing]] | [[Category:Unit testing]] |
Revision as of 19:50, 20 April 2012
Overview
The migration is pretty straightforward:
- create new test file in `xxx/tests/yyy_test.php`
- copy contents of the old test file
- replace
extends UnitTestCase
withextends basic_testcase
andextends UnitTestCaseUsingDatabase
withextends advanced_testcase
- move constructor code to setUp
- fix setUp(), tearDown()
- fix assert syntax
- add $this->resetAfterTest() in advanced test cases that modify database
- add missing global $CFG for includes outside of testcase classes
Assert differences
SimpleTest emulation
SimpleTest | PHPUnit | Notes |
---|---|---|
$this->assertEqual($expected, $actual)
|
$this->assertEquals($expected, $actual)
|
|
$this->assertIdentical($expected, $actual)
|
$this->assertSame($expected, $actual)
|
|
$this->assertTrue($actual)
|
$this->assertTrue((bool)$a, $b)
|
SimpleTest convers parameter to bool. |
$this->assertFalse($actual)
|
$this->assertFalse((bool)$a, $b)
|
SimpleTest convers parameter to bool. |
$this->expectException(true)
|
$this->setExpectedException('exception_name')
|
|
$this->expectError()
|
$this->setExpectedException('PHPUnit_Framework_Error')
|