Issue
Hello Every One I Have This Method Which it Checks if the Input String Is Numbers only And Its Return True Or False I Want To Make A Junit Test For this method and Actually I Don't know how to test Method Like This Can Any One Help And Thank You All. My Method:
private Boolean Check_Ean(String EAN_Ch)
{
Long EAN;
try
{
EAN = Long.parseLong(EAN_Ch);
return true;
}
catch (NumberFormatException e)
{
return false;
}
}
Solution
First you need to create a class in the test folder(located at the same path as main). Then you need to use their annotations to or either Prepare the information, Test and Destroy the information(usefull when you have DB connection opens or streams):
public class TestClass {
@Before
public void setup() {
//prepare information
}
@Test
public void testCheck_Ean() {
boolean result = Check_Ean(...);
Assert.assertTrue(result);
}
@After
public void destroy() {
//if you need to "destroy" some info
}
}
Answered By - Juan Ramos
Answer Checked By - Cary Denson (JavaFixing Admin)