간단한 서비스 클래스 인 AnalyzerService는 데이터베이스에 저장된 proc를 호출합니다. 통합 테스트를 실행하여 분석기 클래스가 작동 한 후에 저장된 proc 및 올바른 데이터가 서비스 호출을 호출하도록 시도합니다. 그러나 "null 객체에서 calculateEstimateNumberOfPositions() 메서드를 호출 할 수 없습니다"라는 두려운 예외가 발생합니다. 서비스 객체가 null 인 이유는 무엇입니까? 내가 뭘 놓치고 있니?Grails 통합 테스트가 null 서비스 객체에 대한 메소드를 호출 할 수 없습니까?
고맙습니다.
package foobar.analyze
import static org.junit.Assert.*
import org.junit.*
import foobar.analyze.AnalyzerService
//@TestFor(AnalyzerService)
class AnalyzerServiceTests {
def AnalyzerService service
def dataSource
@Before
void setUp() { }
@After
void tearDown() { }
@Test
void testcalculateEstimateNumberOfPositions() {
String positionName = "crew"
String city = "Great Neck"
String state = "NY"
int numberOfPositionsSought = 100
int expectedNumberOfPositionsEstimate = 100
def numberOfPositionsEstimate = service.calculateEstimateNumberOfPositions(positionName, city, state, numberOfPositionsSought)
fail (numberOfPositionsEstimate != expectedNumberOfPositionsEstimate)
}
}
이 경우 컨벤션이 중요하지만 "컨벤션에서 벗어나면 야생에서 벗어날 것"이라는 일반 성명이 너무 강합니다. 표준 접근 방식이 당신을 위해 작동하지 않을 때 컨벤션을 돌아 다니고 싶을 때가 많이 있습니다. 그냥이 경우에는 안된다 :) –
@ BurtBeckwith 맞아, 고마워. 나는 10 개월 째 부모님을 양육하기 때문에 나는 그것을 얻었고 나는 책의 절반 밖에 남지 않았습니다. : P 나는 그것을 합리적인 것으로 업데이트 할 것이다. – dmahapatro
감사합니다! 네, 우리의 단위 테스트에서 서비스를 사용하고있는 다른 프로젝트 중 하나에서 예. 10MO에 관해서는, 나는 같은 시간이 끝난 후 출산 휴가에서 돌아오고있다. – Alexx