RE: Null pointer exception when running the first junit test

Hi
When i’m running the first junit test im getting null pointer exception. I have copied it below. Please find why I’m getting this error.

 


package Application.UnitTests;
import static org.junit.Assert.*;

import junit.extensions.*;

import org.junit.Test;

import Application.MathProvider;
public class JunitMathProvider_1 {
MathProvider provider;
public SimpleTest(){

provider = new MathProvider();

}
@Test

public void add()

{

System.out.println("Starting test " + new Object(){}.getClass().getEnclosingMethod().getName());

int firstNumber = 10;

int secondNumber = 20;

assertEquals(firstNumber + secondNumber, provider.Add(firstNumber, secondNumber));

System.out.println("Ending test " + new Object(){}.getClass().getEnclosingMethod().getName());

}
}

saikrishtest Default Asked on October 26, 2014 in Selenium WebDriver.

Hi
OnĀ  Which Line Your are Getting Null Pointer Exception..?

on October 26, 2014.
Add Comment
2 Answers

HI
Try Writing This Line as First Line in Add Method
provider = new MathProvider();

Please Let me Know if it Works

Regards
ankit

Vice Professor Answered on October 26, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.