What are the consequences of not naming PHPUnit test methods with camel case?
I'm writing unit tests with PHPUnit.
I now have about 100 methods written.
Since these are for a Kohana framework application, I used its naming convention for the test methods as well, e.g.:
function test_instance()
{
...
}
function test_config()
{
...
}
All my tests run fine in Eclipse and from the command line.
However, I now need to use a setup function and realized that it only works when named:
function setUp()
{
...
}
and not:
function set_up()
{
...
}
Now I am wondering if I will h开发者_Go百科ave any disadvantages down the road if I don't rename all of my PHPUnit methods so that they are camel case, e.g. do other tools that use PHPUnit excect the method names to be in camelcase notation?
Method names in PHP are not case-sensitive, so it doesn't matter whether you use setup
or setUp
and tearDown
or teardown
. However, you may not use set_up
or tear_down
, because that is a different name. PHPUnit calls setUp
and tearDown
between each test to guarantee the environment.
By convention PHPUnit considers any method starting with test
to be a Test. You can omit the prefix by using the @test
annotation in the method DocBlock. PHPUnit will transform CamelCased method names to spaced descriptions when printing any reports, so testMethodDoesThis
will appear as "Method Does This".
CamelCase will also affect tests annotated with the @testDox
annotation.
setUp
and teardown
are exact names that have to be matched in order to be recognized. Tests, on the other hand, just have to begin with test
. (All of these are case-sensitive.)
Aside from that, no requirements on the capitalization/layout of the rest of naming. (Well, classes can't start with Test
, but that's about it.)
精彩评论