テストを充実させる
テストと一言で言っても
単体テスト、結合テスト、システムテスト、受け入れテスト・・・etc
色々とあるわけですが、一番効果が出るのはいったいどこなんでしょう
受け入れテストでしょうか
前職(SIer)では単体テストのカバレッジ100%を強いられていましたが
100%にするだけでは、テストの意味が無く、後工程で結局「バグがぁー」ってなる。
であれば、単体テストはそこそこに実際の動きをテストするのがいいのではないかと思う今日このごろ。
実際の動きというと、ブラウザを使用して挙動を確認するということ
で、使うのが Selenium + Scalatest です。
こんな感じでスクリーンショットを取りながら自動でテストが出来ます。
import org.scalatest.{ BeforeAndAfterAll, FunSpec } import org.scalatest.Matchers._ import org.scalatest.selenium.WebBrowser import org.openqa.selenium.{By, Keys, WebDriver} import org.openqa.selenium.firefox.FirefoxDriver import org.openqa.selenium.support.ui.{ ExpectedConditions, WebDriverWait } class SampleSpec extends FunSpec with WebBrowser with BeforeAndAfterAll { implicit val webDriver: WebDriver = new FirefoxDriver describe("Stanby") { it("Take Screenshot") { setCaptureDir("./pic") go to ("https://jp.stanby.com/") pageTitle should be ("スタンバイ 日本最大級の求人検索エンジン") val query = "エンジニア" click on "q" textField("q").value = "エン" val element = webDriver.findElement(By.name("q")) element.sendKeys(Keys.ARROW_LEFT) capture to "captureX" enter(s"$query") capture to "capture3" submit() (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.titleContains(s"${query}の求人")) pageTitle should be (s"${query}の求人| スタンバイ") capture to "capture2.png" } } override def afterAll(): Unit = webDriver.quit() }
BDDについても学んで振る舞いのテストを充実させたいです。
※追記
こんな記事ありました
- 作者: 高橋寿一
- 出版社/メーカー: 翔泳社
- 発売日: 2014/01/08
- メディア: Kindle版
- この商品を含むブログを見る
Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing
- 作者: David Sale
- 出版社/メーカー: Wiley
- 発売日: 2014/07/03
- メディア: Kindle版
- この商品を含むブログを見る