Reputation: 103
I have a scenario where I need to stop the execution once it reaches one of the condition in else part. Below is my code.Once the condition reaches else,i want to stop the execution.How do I use assert condition for this?
So once I reach last condition ,that is if any employee reaches Exception,I want to stop the execution
If a condition reaches,HR department,variable counter will be incremented by 1 and if it reaches Finance department ,variable i will be decremented by 1
for (int i=0;i<EmployeeID.size();i++) {
//while(i++<=EmployeeID.size()) {
if(counter==EmployeeID.size())break;
stmt = con.prepareStatement("select * from Employee where EmployeeID=?");
stmt.setInt(1,EmployeeID.get(i));
//System.out.println(EmployeeID.get(i));
rs3= stmt.executeQuery();
// while(counter!=EmployeeID.size()) {
while(rs3.next()) {
getCurrentQueueID= rs3.getString("CurrentQueueID");
if(getCurrentQueueID.equals("1")) {
log.info(+EmployeeID.get(i) + " is in HR Department");
counter++;
//System.out.println("Count is"+counter);
}
else if(getCurrentQueueID.equals("7")) {
log.info(+EmployeeID.get(i) + " is in Finance Department");
--i;
System.out.println("Value of i is" +i);
Thread.sleep(10000);
}
else if(getCurrentQueueID.equals("3")) {
log.info(+EmployeeID.get(i) + " is in Exception");
}
} //End of While rs loop
Upvotes: 1
Views: 2912
Reputation: 8686
If you want to stop test so that it is not considered failed then just use return;
statement.
If you need to stop test as failed then you either:
assert false;
statement if you do not use any test frameworkorg.junit.Assert.fail();
if you use JUnitorg.testng.Assert.fail()
if you use TestNGUpvotes: 1