[英]Why does my Unit Test keep saying NullPointerException? I'm using @BeforeClass and it doesn't seem to work
public class FlooringMasteryServiceLayerImplTest {
private FlooringMasteryServiceLayer service;
/*public FlooringMasteryServiceLayerImplTest() {
ApplicationContext ctx
= new ClassPathXmlApplicationContext("applicationContext.xml");
service
= ctx.getBean("serviceLayer", FlooringMasteryServiceLayer.class);
}*/
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testCreatedOrderFileNameFromDate() {
LocalDate date = LocalDate.parse("2020-11-25");
String orderFileName = service.createOrderFileNameFromDate(date);
assertEquals(orderFileName, "Orders_11252020.txt", "The order file name generated was incorrect.");
}
}
I can't seem to find what the solution is for this Failed Unit Test.我似乎找不到这个失败的单元测试的解决方案。 I have @BeforeClass so I believe it is running JUnit4.我有@BeforeClass,所以我相信它正在运行 JUnit4。 It just keeps saying NullPointerException and I don't know how to solve this issue.它只是一直说 NullPointerException 我不知道如何解决这个问题。 Please help请帮忙
are you instantiating the service object?您是否正在实例化服务 object?
You need to initialize your variable "service" inside @BeforeClass method.您需要在 @BeforeClass 方法中初始化变量“服务”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.