Hello kberov,
First of all, congratulation for the [i18nl10n] module!
About UnitTest I wrote the same topic as you in the french forum 2 month ago :
http://forum.contao.fr/extensions/co...res-t1529.html
If you don't talk french the main point is that oelmekki made a great module :
https://github.com/oelmekki/typolight_testing
This is not so simple to use but really powerful, based on selenium and you can use MockObject.
For small project I'm using NetBean's with phpunit. You can write UnitTest in method comment and NetBean's can generate it!
Code:
/**
* Give the last day of the given month.
* @return int (28,29,30,31).
* @assert (2,2009) == 28
* @assert (2,2008) == 29
* @assert (4,2010) == 30
* @assert (7,2008) == 31
* @assert (8,2008) == 31
* @assert (7,2010) == 31
* @assert (8,2010) == 31
* @assert (9,2008) == 30
* @assert (12,2010) == 31
* @assert (1,2011) == 31
*/
public static function get_last_day_of_month($month, $year) {
return date('t', mktime(0, 0, 0, $month, 1, $year));
}
Will generate :
Code:
/**
* Generated from @assert (2,2009) == 28.
*/
public function testGet_last_day_of_month() {
$this->assertEquals(
28,
tool_date::get_last_day_of_month(2, 2009)
);
}
/**
* Generated from @assert (2,2008) == 29.
*/
public function testGet_last_day_of_month2() {
$this->assertEquals(
29,
tool_date::get_last_day_of_month(2, 2008)
);
}
/**
* Generated from @assert (4,2010) == 30.
*/
public function testGet_last_day_of_month3() {
$this->assertEquals(
30,
tool_date::get_last_day_of_month(4, 2010)
);
}
/**
* Generated from @assert (7,2008) == 31.
*/
public function testGet_last_day_of_month4() {
$this->assertEquals(
31,
tool_date::get_last_day_of_month(7, 2008)
);
}
/**
* Generated from @assert (8,2008) == 31.
*/
public function testGet_last_day_of_month5() {
$this->assertEquals(
31,
tool_date::get_last_day_of_month(8, 2008)
);
}
/**
* Generated from @assert (7,2010) == 31.
*/
public function testGet_last_day_of_month6() {
$this->assertEquals(
31,
tool_date::get_last_day_of_month(7, 2010)
);
}
/**
* Generated from @assert (8,2010) == 31.
*/
public function testGet_last_day_of_month7() {
$this->assertEquals(
31,
tool_date::get_last_day_of_month(8, 2010)
);
}
/**
* Generated from @assert (9,2008) == 30.
*/
public function testGet_last_day_of_month8() {
$this->assertEquals(
30,
tool_date::get_last_day_of_month(9, 2008)
);
}
/**
* Generated from @assert (12,2010) == 31.
*/
public function testGet_last_day_of_month9() {
$this->assertEquals(
31,
tool_date::get_last_day_of_month(12, 2010)
);
}
/**
* Generated from @assert (1,2011) == 31.
*/
public function testGet_last_day_of_month10() {
$this->assertEquals(
31,
tool_date::get_last_day_of_month(1, 2011)
);
}
But what will be interessting is to generate the logic of test and not only the code writing. For example every money value must be tested the same way => no minus value, not more than the double can store...
I will write a message blog about it some day...
If you start to develop something, tell me I'm thinking about it since month.
Bookmarks