2017-07-01 7 views
0

私は単純な文字列を取り、IDでDB内の列を更新するgrailsコントローラを持っています。私は、例えばデータベース列のGrailsコントローラ更新をjUnitにアサートする方法は?

@Test 
void "testUpdateNameOnMonsterById"() { 

    controller.params.id = 8; 
    controller.params.name = 'Godzilla'; 

    controller.updateMosterNameById(); 
    // what are the different jUnit assertetions that need to happen at this point? 

私はDBを照会してのassertEqualsまたはいるassertTrueを行う必要があります....更新が正常に通過したことを確認するには、この操作のためのJUnitテストを書きたいですか?

jUnitがアサートされているサンプルコードは大変ありがたいです。

あなたはスポックと、次のような何かを行うことができます
+0

あなたはスポックを使用していますか? –

答えて

0

import grails.test.mixin.TestFor 
import spock.lang.Specification 

@TestFor(MonsterController) 
class MonsterControllerSpec extends Specification { 

    void "test updateMonsterNameById"() { 
     given: 
      def monsterId = 8 
      def monsterName = 'Godzilla' 
      params.id = monsterId 
      params.name = monsterName 
     when: 
      controller.updateMonsterNameById() 
     then: 
      monsterName == Monster.get(monsterId).name 
    } 
} 
関連する問題