- 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.
推薦閱讀
- Learn ECMAScript(Second Edition)
- ClickHouse性能之巔:從架構設計解讀性能之謎
- PWA入門與實踐
- Boost C++ Application Development Cookbook(Second Edition)
- SpringMVC+MyBatis快速開發與項目實戰
- Pandas Cookbook
- SQL for Data Analytics
- Effective Python Penetration Testing
- Python機器學習經典實例
- SQL Server與JSP動態網站開發
- C專家編程
- Django 3.0應用開發詳解
- 單片機原理及應用技術
- 虛擬現實建模與編程(SketchUp+OSG開發技術)
- Web開發新體驗