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 have 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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With