I am trying to execute a simple testcase using JUnit, but the testcase always passes even in false condition. I am not able to figure out the mistake in my program below. It looks like somewhere there is a mistake with the Scanner class multiple inputs.
I would like to test with multiple inputs to the testcase such that the test case accepts different employee types.
import java.util.Scanner; import static org.junit.Assert.assertEquals; public class EmployeeIdentificationTest extends TestCase { String firstName, middleName,lastName; int age=0; String choice=null; // assigning the values protected void setUp(){ do{ Scanner scanner = new Scanner(System.in); System.out.println("Enter firstName "); firstName= scanner.nextLine(); System.out.println("Enter middleName"); middleName= scanner.nextLine(); System.out.println("Enter lastName"); lastName= scanner.nextLine(); System.out.println("Enter the age"); int flag=0; while(flag==0){ try{ age= scanner.nextInt(); flag=1; } catch(Exception e){ scanner.nextLine(); System.out.println("Wrong entry, please enter digits only:"); } } System.out.println("Do you like to fetch more records press Yes or No"); scanner.nextLine(); choice=scanner.nextLine(); }while(choice.contains("Y")||choice.contains("y")); } // test method public void testEmployee(){ String employeeType=EmployeeIdentification.getEmployeeType(firstName, middleName, powerTrain, age); if(employeeType.equals("Junior Developer")||employeeType.equals("Senior Developer")||employeeType.equals("System Analyst")||employeeType.equals("Manager")||employeeType.equals("Delivery Head")) assert(true); } }