[Tamnx] Unit test homework#28
[Tamnx] Unit test homework#28tamnx-1149 wants to merge 6 commits intosun-unit-test-training:masterfrom
Conversation
| use Tests\TestCase; | ||
| use InvalidArgumentException; | ||
|
|
||
| class ProductServiceTest extends TestCase |
There was a problem hiding this comment.
Ở đây thiếu miss mất 1 case.
Giả sử các trường hợp dưới đây không tồn tại thì ra sao?
$totalProducts[Product::CRAVAT_TYPE]
$totalProducts[Product::OTHER_TYPE]
$totalProducts[Product::WHITE_SHIRT_TYPE]
Ngoài thì cũng nên để ý các trương logic so sánh >= hiện tại chỉ đang test các trường hợp > nhưng đối với các trường hợp = thì đang không test
| public function test_index_return_view_success() | ||
| { | ||
| $expected = CalendarService::COLOR_BLACK; | ||
| $this->calendarService->shouldReceive('getDateClass')->andReturn($expected); |
There was a problem hiding this comment.
Trong controller này có logic, nên phải làm sao test đưuọc cả logic đấy. Muốn test được logic đấy thì có 2 cách
1 là cái mock này không nên chỉ shouldReceive và andReturn luôn.
Mình nên làm để biết thêm là cái method getDateClass gọi bao nhiêu lần và những tham số truyền vào là gì
2 là
$response->assertViewHas('calendars'); thì mình phải assert xem cả cái data của nó nữa
| $this->assertEquals($result, $infoBill); | ||
| } | ||
|
|
||
| public function provider_input_discount(): array |
There was a problem hiding this comment.
Để ý các logic >= phải test 2 case > và case =
| $this->assertEquals($result, $time); | ||
| } | ||
|
|
||
| public function provider_input_for_calculate() |
There was a problem hiding this comment.
Ở đây sẽ có 1 case, là giả sử không truyền vào has_watch thì kết quả sẽ ra sao.
Tất nhiên là không truyền vào has_watch thì default nó là false thì nó sẽ trùng 1 trong các số test của mình. Nhưng về cơ bản thì vẫn phải có case là không truyền vào cái gì cả
| $this->assertEquals('exercise08::index', $response->getName()); | ||
| } | ||
|
|
||
| public function test_calculate_price_return_success() |
| use Tests\TestCase; | ||
| use InvalidArgumentException; | ||
|
|
||
| class TicketServiceTest extends TestCase |
| */ | ||
| public function test_calculate_return_exception($input) | ||
| { | ||
| $this->expectException(InvalidArgumentException::class); |
There was a problem hiding this comment.
Exception có message nên cũng phải test luôn message cho exception
Purpose/Notes
Screenshot
(UI, coverage screenshot?)

Checklist (*)