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

Wow dat worked..Thanks Ankit.

I’m not able to understand what caused the issue. Can u please explain it.

Thanks,
Sai Krishna.

Default Answered on October 26, 2014.

Hi Simple_Test Method was Never Called and  Object is Initialized With in That Method , So Object is Never Initialized and You were Trying To use that ObjectRegards Ankit

on October 26, 2014.

Hi SaiKrishTest,

Please close the question now, take a look how to do it:
http://forumsqa.com/selenium-webdriver/how-to-choose-best-answer-insert-code-vote-up-an-answer/

Regards,
Lakshay Sharma

on October 27, 2014.
Add Comment

Your Answer

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