Splitting up assertions in unit tests

Open
#2,338 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
elasticsearch, php
Domain
testing

Research direction

Start in tests/php/TestElasticsearch.php at testGetDocuments and review how it covers retrieving documents, missing documents, and empty IDs. Identify other unit tests with similarly mixed cases, then separate those cases so failures identify one scenario; the focused tests should all pass independently.

Written by the indexing model from the issue text.

Description

enhancement needs tests

Is your enhancement related to a problem? Please describe.

Describe the solution you'd like
Some unit tests are testing different cases in one method. For example, testGetDocuments tests retrieving documents, retrieving a document that doesn't exist, and passing an empty id to retrieve a document.

When this test doesn't pass, it's not clear exactly which case have failed:

1) ElasticPressTest\TestElasticsearch::testGetDocuments
Failed asserting that 2 matches expected 3.

So, we could try to split up assertions a little to have more focused tests.

Designs

Describe alternatives you've considered

Additional context

Dominant language
PHP
Stars
1.3k
Forks
325
Avg merge
2d 11h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 10up/ElasticPress

All issues in 10up/ElasticPress

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.