Mais conteúdo relacionado
Semelhante a Gws in fukuoka (20)
Gws in fukuoka
- 1. Java のコードを 1/4 にする
グルービーなテスト
を導入しよう!
2012/09/01 G* ワークショップ in 福岡
綿引 琢磨
- 8. グルービーなテスト
Groovy を利用する
Power Assert
Spock Framework を利用する
Mock, Data Driven Testing, Functional Testing
Geb + テストフレームワーク を利用する
Page Object with Spock
- 10. Power Assert によるテスト
import org.junit.Test
class CampaignRateTest {
! private CampaignRate testee = new CampaignRate()
! @Test
! public void testGetRateWithBook_Assert() {
! ! Cart cart1 = createCart true, 5, 3000
! ! assert testee.getRateWithBook(cart1) == 5
! }
! def createCart(existBooks, itemCount, totalPrice) {
! ! Cart cart = new Cart()
! ! cart.setExistBooks existBooks
! ! cart.setItemCount itemCount
! ! cart.setTotalPrice totalPrice
! ! cart
! }
}
- 13. Spock による Mock テスト
import spock.lang.Specification
class CampaignRateMockSpec extends Specification {
! CampaignRate testee = new CampaignRate()
! def "Mockを用いて、カート内にキャンペーン商品が存在するかを確認する。"() {
! ! setup:
! ! ItemCheck cart = Mock()
! ! cart.existBooks() >> true
! ! expect:
! ! testee.hasCampaignItem(cart) == true
! }
}
- 15. Spock による機能テスト
import spock.lang.Specification
class StackSpec extends Specification {
def stack = new Stack()
! def "push したものは、peek により取り出せる" () {
! ! when:
! ! stack.push "something"
! ! then:
! ! stack.size() == 1
! ! stack.peek() == "something"
! }
}
- 18. Geb + Spock によるWebテスト
import geb.spock.GebReportingSpec
import org.jggug.demo.pages.*
class WebTestSpec extends GebReportingSpec {
def "Hello画面で[JGGUG]と入力しgreetボタンを押すと Greet画面に遷移し[Hello, JGGUG]と表示する。"() {
when:
to HelloPage
username = 'JGGUG'
and:
greetButton.click()
then:
at GreetingPage
and:
h1Text == 'Hello, JGGUG!'
}
}
- 20. Java のコードを 1/4 にする
グルービーなテスト
を導入しよう!
2012/09/01 G* ワークショップ in 福岡
綿引 琢磨
Notas do Editor
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n