2
votes

I'm learning how to test in PHPUnit and I'm wondering I want to know if there is a "best practice" when it comes to naming PHPUnit test methods. Should they just be named the same as the method being tested? For example should this method

getView()

be named

testGetView()

or should the name be more descriptive?

1

1 Answers

2
votes

A unit test usually has a method under test (getView), a context (invalid view) and an expected outcome (errors out).

I like to separate these three with underscore and use camel case as a word separator. e.g. testGetView_InvalidView_ErrorsOut

Most people just use camelcase to separate everything e.g. testGetViewInvalidViewErrorsOut

As long as you are consistent with yourself, you should be fine, though.