Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Conversation

kazuhiro4949
Copy link
Collaborator

@kazuhiro4949 kazuhiro4949 commented Jul 17, 2021

Issue 番号 / Issue ID

目的 / Purpose

ライセンス同意画面ではライセンスの同意後に通信を行い、成功時と失敗時に表示を出し分けています。
ここの分岐部分の仕様に関してユニットテストを追加しました。

破壊的変更をもたらしますか / Does this introduce a breaking change?

[ ] Yes
[x] No

Pull Request の種類 / Pull Request type

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[x] Other... Please describe: Unit Test

検証方法 / How to test

以下で今回作成したテストが通るのを確認しています

dotnet test Covid19Radar/Tests/Covid19Radar.UnitTests

コードの入手 / Get the code

git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
dotnet restore

コードの検証 / Test the code

dotnet test Covid19Radar/Tests/Covid19Radar.UnitTests

確認事項 / What to check

  • Xamarinの開発環境にあまりなれていないため、コーディングスタイルやテストの実装方法、ユニットテストの検証項目に不備がないか確認いただけると嬉しいです

その他 / Other information

@keiji keiji self-requested a review July 18, 2021 09:54
@@ -0,0 +1,108 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

ライセンス通知ヨシッ

Comment on lines 44 to 48
mockUserDataService.Reset();
mockUserDialogs.Reset();
mockNavigationService.Reset();
mockLoggerService.Reset();
mockTermsUpdateService.Reset();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpickですが、ここの並びはクラスのメンバ変数の宣言の並びと合わせておくと、将来的に記述漏れに気づきやすそうです。

Comment on lines 71 to 74
.Returns(Task.Run(() =>
{
return true;
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

一行で書いてしまった方がシンプルかもしれません(意図がつかみにくくなる・他と記述を合わせたなどの理由がある場合はこのままで)

Suggested change
.Returns(Task.Run(() =>
{
return true;
}));
.Returns(Task.Run(() => true));

Comment on lines 93 to 96
.Returns(Task.Run(() =>
{
return false;
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

ここも同様につぎのようにも書けます。

Suggested change
.Returns(Task.Run(() =>
{
return false;
}));
.Returns(Task.Run(() => false));

* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System;
Copy link
Collaborator

Choose a reason for hiding this comment

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

使っていないようなので削除してください。

using Covid19Radar.ViewModels;
using Moq;
using Prism.Navigation;
using Xamarin.Essentials;
Copy link
Collaborator

Choose a reason for hiding this comment

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

使っていないようなので削除してください。

@kazuhiro4949
Copy link
Collaborator Author

何回かに一回テストがコケることが発覚したので一旦draftに戻しますmm (原因不明...)

@kazuhiro4949 kazuhiro4949 marked this pull request as draft August 7, 2021 11:45
}

[Fact]
public void Dispose()
Copy link

Choose a reason for hiding this comment

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

UserDialogs.Instanceのnullクリアが必要です。
逆にほかは毎回初期化されるものなので、ある分には問題ありませんが無くても良いです。

mockTermsUpdateService = mockRepository.Create<ITermsUpdateService>();
}

[Fact]
Copy link

@ghost ghost Apr 18, 2022

Choose a reason for hiding this comment

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

テストコード(テスト用のメソッド)ではないので[Fact]は不要です。


namespace Covid19Radar.UnitTests.ViewModels
{
public class TutorialPage3ViewModelTests
Copy link

Choose a reason for hiding this comment

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

IDisposableを継承する必要があります。(Dispose()が呼ばれません)


mockUserDataService
.Setup(product => product.RegisterUserAsync())
.Returns(Task.Run(() => { return true; }));
Copy link

Choose a reason for hiding this comment

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

非同期メソッドの戻り値の設定にはReturnsAsync()が使えるかと思います。

mockUserDialogs.Verify(x => x.HideLoading(), Times.Once());
mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny<string>(), It.IsAny<string>(), "OK", null), Times.Never());

mockNavigationService.Verify(x => x.NavigateAsync("PrivacyPolicyPage"), Times.Once);
Copy link

Choose a reason for hiding this comment

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

Times.OnceはメソッドですのでTimes.Once()でお願いします。
※他も同様の箇所の対応をお願いします

@keiji keiji self-assigned this Apr 20, 2022
@keiji
Copy link
Collaborator

keiji commented Apr 20, 2022

まずはじめにこちらcocoa-mhlwのブランチにマージして作業を続けます。

@keiji keiji changed the base branch from develop to feature/kazuhiro4949_tutorialpage3viewmodel_naivation_test April 20, 2022 03:53
@keiji keiji marked this pull request as ready for review April 20, 2022 03:54
@keiji keiji merged commit 89b9604 into cocoa-mhlw:feature/kazuhiro4949_tutorialpage3viewmodel_naivation_test Apr 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ユニットテストの拡充 (TutorialPage3ViewModel)
2 participants