简单的服务类 AnalyzerService 调用存储在数据库中的过程。尝试运行集成测试以确保服务调用存储的过程并在分析器类对其进行操作后返回正确的数据。但是,得到“无法在空对象上调用方法 calculateEstimateNumberOfPositions()”的可怕异常。为什么服务对象为空?我错过了什么?
谢谢你!
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)
}
}