0
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. It just keeps saying NullPointerException and I don't know how to solve this issue. Please help

Pavan Dittakavi
  • 2,784
  • 5
  • 25
  • 41
Chris D.
  • 13
  • 4
  • What are you expecting `@BeforeClass` to do? – tgdavies Nov 30 '21 at 05:19
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – tgdavies Nov 30 '21 at 05:22
  • I just want my unit test to work and also understand why it wasn't working in the first place and why it is displaying a NullPointerException. – Chris D. Nov 30 '21 at 05:24
  • service is never initialized. – Jens Nov 30 '21 at 05:45

1 Answers1

0

You need to initialize your variable "service" inside @BeforeClass method.

HaroldSer
  • 1,952
  • 2
  • 11
  • 22