uuid: - value: 80c27b8b-ebb6-486e-9fb8-a4d29ade396c langcode: - value: en type: - target_id: daily_email target_type: node_type target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 revision_timestamp: - value: '2025-05-11T09:00:28+00:00' revision_uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 revision_log: { } status: - value: true uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 title: - value: | Writing good test names created: - value: '2023-11-18T00:00:00+00:00' changed: - value: '2025-05-11T09:00:28+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2023/11/18/writing-good-test-names langcode: en body: - value: |

In PHPUnit, there are different ways to write test methods.

The standard way is to use camel-case method names with a test prefix, for example:

public function testTheProjectNameShouldBeAString(): void
      {
          // ...
      }
      

Another popular way, particularly in some frameworks, is to use snake-case method names:

/** @test */
      public function the_project_name_should_be_a_string(): void
      {
          // ...
      }
      

This may be more readable but only works if the @test annotation is present.

What if you need to add another annotation, such as @dataProvider to the test? Do you do multi-line docblocks everywhere, or mix and match single and multiple line docblocks depending on the test?

Here's the thing

My preference switches between both ways of writing test methods.

But, whichever way I write it, I write descriptive method names that explain what the test does - even if it means having a long method name.

I avoid short and generic names like testUpdate().

People should be able to read the test name and understand what it does and what it's testing.

format: full_html processed: |

In PHPUnit, there are different ways to write test methods.

The standard way is to use camel-case method names with a test prefix, for example:

public function testTheProjectNameShouldBeAString(): void
      {
          // ...
      }
      

Another popular way, particularly in some frameworks, is to use snake-case method names:

/** @test */
      public function the_project_name_should_be_a_string(): void
      {
          // ...
      }
      

This may be more readable but only works if the @test annotation is present.

What if you need to add another annotation, such as @dataProvider to the test? Do you do multi-line docblocks everywhere, or mix and match single and multiple line docblocks depending on the test?

Here's the thing

My preference switches between both ways of writing test methods.

But, whichever way I write it, I write descriptive method names that explain what the test does - even if it means having a long method name.

I avoid short and generic names like testUpdate().

People should be able to read the test name and understand what it does and what it's testing.

summary: null field_daily_email_cta: { }