测试驱动开发TDD(3)
作者:网络转载 发布时间:[ 2014/1/20 15:46:21 ] 推荐标签:测试技术
实现GameManager让测试通过。
public class GameManager
{
private readonly IGuesser guesser;
public bool IsGameOver { get; private set; }
private const int MAX_TIMES = 6;
private int times;
public GameManager(IGuesser guesser)
{
this.guesser = guesser;
}
public void Guess(string input)
{
times++;
IsGameOver = times == MAX_TIMES;
guesser.Guess(input);
}
}
ok
猜测数字
输入验证
生成答案
输入次数
输出猜测结果
输入猜测结果。这里包含一个猜对的情况下应该返回"you win"并且Gameover。其他输入返回的结果,在Guesser和validator中已经Cover了。挑几个来测试一下输入输出。
[TestClass]
public class GameManagerTest
{
private _gameManager _game;
[TestInitialize]
public void Init()
{
IGuesser guesser = new Guesser(new AnswerGeneratorForTest());
_game = new _gameManager(guesser);
}
[TestMethod]
public void should_return__game_over_when_input_times_is_six_and_result_is_wrong()
{
const string input = "1368";
const int maxtimes = 6;
var actual = false;
for (var time = 0; time < maxtimes; time++)
{
_game.Guess(input);
}
actual = _game.Is_gameOver;
Assert.AreEqual(true, actual);
}
[TestMethod]
public void should_return_you_win_and__game_is_over_when_input_is_equal_answer_number()
{
const string input = "2975";
var actual = _game.Guess(input);
Assert.AreEqual("You win!", actual);
Assert.AreEqual(true, _game.Is_gameOver);
}
[TestMethod]
public void should_return_try_again_input_must_be_four_digits_when_input_is_not_equal_four_digits()
{
const string input = "15243";
var actual = _game.Guess(input);
Assert.AreEqual("try again the input must be four digits.", actual);
}
[TestMethod]
public void should_return_try_again_input_can_not_be_empty_when_input_is_empty()
{
const string input = "";
var actual = _game.Guess(input);
Assert.AreEqual("try again the input can't be empty.", actual);
}
[TestMethod]
public void should_return_try_again_input_must_be_fully_digital_when_input_is_not_all_digital()
{
const string input = "a4sw";
var actual = _game.Guess(input);
Assert.AreEqual("try again the input must be fully digital.", actual);
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11