Skip to content

[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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tamnx-1149
Copy link

@tamnx-1149 tamnx-1149 commented May 21, 2021

Purpose/Notes

Screenshot

(UI, coverage screenshot?)
image

Checklist (*)

  • Pull request has been self-reviewed
  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All CI builds passed successfully (all builds are green)

@tamnx-1149 tamnx-1149 marked this pull request as ready for review May 21, 2021 06:40
use Tests\TestCase;
use InvalidArgumentException;

class ProductServiceTest extends TestCase
Copy link

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);
Copy link

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ỉ shouldReceiveandReturn 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
Copy link

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()
Copy link

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ả

Copy link

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()
Copy link

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
Copy link

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);
Copy link

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

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