82 lines
2.9 KiB
YAML
82 lines
2.9 KiB
YAML
uuid:
|
|
- value: c2315804-efa4-4b5e-ae67-41457d8cd8c8
|
|
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:22+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: 'Tests can assert multiple things'
|
|
created:
|
|
- value: '2024-01-19T00:00:00+00:00'
|
|
changed:
|
|
- value: '2025-05-11T09:00:22+00:00'
|
|
promote:
|
|
- value: false
|
|
sticky:
|
|
- value: false
|
|
default_langcode:
|
|
- value: true
|
|
revision_translation_affected:
|
|
- value: true
|
|
path:
|
|
- alias: /daily/2024/01/19/tests-can-assert-multiple-things
|
|
langcode: en
|
|
body:
|
|
- value: |
|
|
<p>Similar to "a method should only have one return statement", I've seen similar advice when working with tests: "Tests should only have a single assertion".</p>
|
|
|
|
<p>I don't think this is true, and in my experience, you need multiple assertions to have a thorough test.</p>
|
|
|
|
<p>And, whilst similar assertions add some duplication, they can make the intent clearer and give better error messages.</p>
|
|
|
|
<p>Instead, I focus on one test case per test.</p>
|
|
|
|
<p>If I'm testing the following:</p>
|
|
|
|
<ul>
|
|
<li>A blog page exists.</li>
|
|
<li>Only post nodes are visible.</li>
|
|
<li>Only published posts are visible,</li>
|
|
<li>Posts are returned in a specified order.</li>
|
|
</ul>
|
|
|
|
<p>These will be split into separate tests - making it easier to read and maintain the code and have faster execution times by running only the tests I want with the minimum amount of code in each - regardless of how many assertions are in each.</p>
|
|
|
|
|
|
format: full_html
|
|
processed: |
|
|
<p>Similar to "a method should only have one return statement", I've seen similar advice when working with tests: "Tests should only have a single assertion".</p>
|
|
|
|
<p>I don't think this is true, and in my experience, you need multiple assertions to have a thorough test.</p>
|
|
|
|
<p>And, whilst similar assertions add some duplication, they can make the intent clearer and give better error messages.</p>
|
|
|
|
<p>Instead, I focus on one test case per test.</p>
|
|
|
|
<p>If I'm testing the following:</p>
|
|
|
|
<ul>
|
|
<li>A blog page exists.</li>
|
|
<li>Only post nodes are visible.</li>
|
|
<li>Only published posts are visible,</li>
|
|
<li>Posts are returned in a specified order.</li>
|
|
</ul>
|
|
|
|
<p>These will be split into separate tests - making it easier to read and maintain the code and have faster execution times by running only the tests I want with the minimum amount of code in each - regardless of how many assertions are in each.</p>
|
|
|
|
|
|
summary: null
|
|
field_daily_email_cta: { }
|