0
我有一個測試集成測試,如下所示。爲什麼命名服務「服務」在集成測試中不起作用?
package bibs
import static org.junit.Assert.*
import groovy.util.GroovyTestCase;
import org.junit.*
class BibsServiceTests extends GroovyTestCase{
BibsService service
@Before
void setUp() {
// Setup logic here
}
@After
void tearDown() {
// Tear down logic here
}
@Test
void testSomething() {
assertEquals service.convertRangeStringToRangeList("asd"), "asd"
}
}
當我運行的集成測試,我得到的錯誤是
Running 1 integration test... 1 of 1
| Failure: testSomething(bibs.BibsServiceTests)
| java.lang.NullPointerException: Cannot invoke method convertRangeStringToRangeList() on null object
at bibs.BibsServiceTests.testSomething(BibsServiceTests.groovy:30)
| Completed 1 integration test, 1 failed in 292ms
| Tests FAILED - view reports in
如果我改變服務的名稱像
BibsService bibsService
然後將試驗比服務以外的東西經過。我想知道爲什麼會出現這種情況?謝謝!