What are the consequences of not naming PHPUnit test methods using a camel case?

I am writing unit tests using PHPUnit .

Now I have written about 100 methods .

Since they are intended for the Kohana application, I used the naming convention for test methods, for example:

function test_instance() { ... } function test_config() { ... } 

All my tests work fine in Eclipse and from the command line.

However, now I need to use the setup function and realized that it only works with the name:

 function setUp() { ... } 

and not:

 function set_up() { ... } 

Now I am wondering if I will have any shortcomings in the future if I do not rename all my PHPUnit methods so that they are a camel body, for example. do other tools that use PHPUnit exclude method names, which should be in the form of camel marking?

+4
source share
2 answers

PHP method names are not case sensitive, so it doesn't matter if you use setup or setup and tearDown or tearDown . However, you cannot use set_up or tear_down because it is a different name. PHPUnit calls setup and tearDown between each test to ensure the environment.

By convention, PHPUnit treats any method starting with test as a test. You can omit the prefix using the @test annotation in the @test method. PHPUnit converts 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.

+12
source

setUp and teardown are the exact names that must be matched for recognition. Tests, on the other hand, just have to start with test . (They are all case sensitive.)

In addition, there is no capitalization / arrangement requirement for the rest of the naming convention. (Well, classes cannot start with test , but more on that.)

+1
source

Source: https://habr.com/ru/post/1335056/


All Articles