- Test-Driven Java Development(Second Edition)
- Alex Garcia Viktor Farcic
- 154字
- 2021-06-24 18:31:52
Implementation
Now that we have a clear definition of when an exception should be thrown, the implementation should be straightforward:
package com.packtpublishing.tddjava.ch03tictactoe; public class TicTacToe { public void play(int x, int y) { if (x < 1 || x > 3) { throw new RuntimeException("X is outside board"); } } }
As you can see, this code does not contain anything else, but the bare minimum required for the test to pass.
Some TDD practitioners tend to take minimum as a literal meaning. They would have the play method with only the throw new RuntimeException(); line. I tend to translate minimum to as little as possible within reason.
We're not adding numbers, nor are we returning anything. It's all about making small changes very fast. (Remember the game of ping pong?) For now, we're doing red-green steps. There's not much we can do to improve this code so we're skipping the refactoring.
Let's move on to the next test.
推薦閱讀
- Windows系統管理與服務配置
- Full-Stack React Projects
- 精通Linux(第2版)
- Learning Unity 2D Game Development by Example
- Advanced Express Web Application Development
- Kubernetes源碼剖析
- Vue.js應用測試
- 寫給程序員的Python教程
- ASP.NET Web API Security Essentials
- Hands-On Robotics Programming with C++
- The Statistics and Calculus with Python Workshop
- 關系數據庫與SQL Server 2012(第3版)
- Python程序設計教程
- Instant AppFog
- Getting Started with Hazelcast