Skip to content

Unit test#6

Open
taipt-0504 wants to merge 1 commit intosun7pro:masterfrom
taipt-0504:unit_test
Open

Unit test#6
taipt-0504 wants to merge 1 commit intosun7pro:masterfrom
taipt-0504:unit_test

Conversation

@taipt-0504
Copy link
Copy Markdown

Purpose/Notes (*)

Unit test for class ProcessRunner

Coverage (*)

(PHPUnit coverage screenshot)
image

Checklist (*)

  • Pull request has been self-reviewed
  • Pull request has a meaningful description of its purpose
  • Pull request has screenshot of phpunit coverage

$this->processRunner = new ProcessRunner();
}

public function testRunWhenIf1TrueAndIf2True()
Copy link
Copy Markdown
Member

@tuanpt-0634 tuanpt-0634 Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nên coi class là Unit cần test, tức class là SUT (System Under Test). Vì thế test case sẽ là test hành vi,không nên quá quan tâm đến tên method là gì, bên trong nó implement như thế nào, khi đó có thể thay đổi cách implement nhưng hành vi không thay đổi nên không phải update lại unit test.

Tên method unit test không cần phải ngắn gọn, nên viết theo snake_case để dễ đọc hơn (có thể config phpcs để bỏ qua naming convention với các method test, xem phpcs.xml)

Có 1 cách đặt tên như thế này: Test It <expected result> When <input are ...>

=> Test It called process1 and process3 When input1 is 12 and input2 can be whatever

Suggested change
public function testRunWhenIf1TrueAndIf2True()
public function test_IT_called_process1_and_process3_WHEN_input1_is_12_input2_is_whatever()

Tên test case cho thấy rõ ràng expect là gì.

{
$result = $this->processRunner->run(12, 3);

$this->assertEquals(2, $result);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chưa đủ assert, vì không ở test case dưới https://github.com/sun7pro/phpunit-training-coverage/pull/6/files#diff-2ccad413df4fa96d3b36fd1b9389b09fR29 kết quả trả về vẫn là 2, làm sao để phân biệt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants