-
Notifications
You must be signed in to change notification settings - Fork 59
[Tamnx] Unit test homework #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
use Tests\TestCase; | ||
use InvalidArgumentException; | ||
|
||
class ProductServiceTest extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ở đâ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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Để ý 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ở đâ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ả
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ngoài ra còn các case >=
nữa
$this->assertEquals('exercise08::index', $response->getName()); | ||
} | ||
|
||
public function test_calculate_price_return_success() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thiếu assert cho session
use Tests\TestCase; | ||
use InvalidArgumentException; | ||
|
||
class TicketServiceTest extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Để ý các case >=
*/ | ||
public function test_calculate_return_exception($input) | ||
{ | ||
$this->expectException(InvalidArgumentException::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception có message nên cũng phải test luôn message cho exception
Purpose/Notes
Screenshot
(UI, coverage screenshot?)

Checklist (*)