- #1
zak100
- 462
- 11
Hi,
I want to create test cases for the following class:
I used NetBeans to generate the test class:
However when I am executing the code it's saying that test has failed. I tried with another test:
but still it's saying that test failed. Please guide me how to correct this problem.
Zulfi.
I want to create test cases for the following class:
Java:
public class PrintGrades {
String strGrade="";
String Method(int iMarks){
if(iMarks > 93){
strGrade ="A";
return "A";
}
else if(iMarks >83){
return "B";
}
else if(iMarks > 73){
strGrade ="B";
return "C";
}
return strGrade;
}
}
I used NetBeans to generate the test class:
Code:
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author HP
*/
public class PrintGradesTest {
public PrintGradesTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of Method method, of class PrintGrades.
*/
@Test
public void testMethod() {
System.out.println("Method");
int iMarks = 0;
PrintGrades instance = new PrintGrades();
String expResult = "";
String result = instance.Method(iMarks);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
}
However when I am executing the code it's saying that test has failed. I tried with another test:
Code:
public void testMethod() {
System.out.println("Method");
int iMarks = 95;
PrintGrades instance = new PrintGrades();
String expResult = "A";
String result = instance.Method(iMarks);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
but still it's saying that test failed. Please guide me how to correct this problem.
Zulfi.