- 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.
推薦閱讀
- INSTANT Mock Testing with PowerMock
- Visual C++程序設(shè)計(jì)學(xué)習(xí)筆記
- Learning Apex Programming
- Pandas Cookbook
- 深度學(xué)習(xí)經(jīng)典案例解析:基于MATLAB
- Troubleshooting PostgreSQL
- 軟件架構(gòu):Python語言實(shí)現(xiàn)
- Hands-On Natural Language Processing with Python
- 愛上micro:bit
- Building Machine Learning Systems with Python(Second Edition)
- Oracle GoldenGate 12c Implementer's Guide
- Spring MVC+MyBatis開發(fā)從入門到項(xiàng)目實(shí)踐(超值版)
- IoT Projects with Bluetooth Low Energy
- UI設(shè)計(jì)基礎(chǔ)培訓(xùn)教程(全彩版)
- Learning Grunt