-
Notifications
You must be signed in to change notification settings - Fork 111
Add navigation test for TutorialPage3ViewModel #286
Add navigation test for TutorialPage3ViewModel #286
Conversation
@@ -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/. */ |
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.
ライセンス通知ヨシッ
Covid19Radar/Tests/Covid19Radar.UnitTests/Covid19Radar.UnitTests.csproj
Outdated
Show resolved
Hide resolved
mockUserDataService.Reset(); | ||
mockUserDialogs.Reset(); | ||
mockNavigationService.Reset(); | ||
mockLoggerService.Reset(); | ||
mockTermsUpdateService.Reset(); |
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.
nitpickですが、ここの並びはクラスのメンバ変数の宣言の並びと合わせておくと、将来的に記述漏れに気づきやすそうです。
.Returns(Task.Run(() => | ||
{ | ||
return true; | ||
})); |
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.
一行で書いてしまった方がシンプルかもしれません(意図がつかみにくくなる・他と記述を合わせたなどの理由がある場合はこのままで)
.Returns(Task.Run(() => | |
{ | |
return true; | |
})); | |
.Returns(Task.Run(() => true)); |
.Returns(Task.Run(() => | ||
{ | ||
return false; | ||
})); |
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.
ここも同様につぎのようにも書けます。
.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; |
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.
使っていないようなので削除してください。
using Covid19Radar.ViewModels; | ||
using Moq; | ||
using Prism.Navigation; | ||
using Xamarin.Essentials; |
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.
使っていないようなので削除してください。
何回かに一回テストがコケることが発覚したので一旦draftに戻しますmm (原因不明...) |
} | ||
|
||
[Fact] | ||
public void Dispose() |
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.
UserDialogs.Instanceのnullクリアが必要です。
逆にほかは毎回初期化されるものなので、ある分には問題ありませんが無くても良いです。
mockTermsUpdateService = mockRepository.Create<ITermsUpdateService>(); | ||
} | ||
|
||
[Fact] |
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.
テストコード(テスト用のメソッド)ではないので[Fact]
は不要です。
|
||
namespace Covid19Radar.UnitTests.ViewModels | ||
{ | ||
public class TutorialPage3ViewModelTests |
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.
IDisposableを継承する必要があります。(Dispose()
が呼ばれません)
|
||
mockUserDataService | ||
.Setup(product => product.RegisterUserAsync()) | ||
.Returns(Task.Run(() => { return true; })); |
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.
非同期メソッドの戻り値の設定には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); |
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.
Times.Once
はメソッドですのでTimes.Once()
でお願いします。
※他も同様の箇所の対応をお願いします
まずはじめにこちらcocoa-mhlwのブランチにマージして作業を続けます。 |
89b9604
into
cocoa-mhlw:feature/kazuhiro4949_tutorialpage3viewmodel_naivation_test
Issue 番号 / Issue ID
目的 / Purpose
ライセンス同意画面ではライセンスの同意後に通信を行い、成功時と失敗時に表示を出し分けています。
ここの分岐部分の仕様に関してユニットテストを追加しました。
破壊的変更をもたらしますか / Does this introduce a breaking change?
Pull Request の種類 / Pull Request type
検証方法 / How to test
以下で今回作成したテストが通るのを確認しています
コードの入手 / Get the code
コードの検証 / Test the code
確認事項 / What to check
その他 / Other information