Hi,
I have created a following class.
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 want to test with JUnit. It develops the following 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 test, it says test failed. I changed the tester to:
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."` `);`
` ` `}`
Some body please guide me what’s the problem.
Zulfi.