Reputation: 6940
I'm trying to run a test using JUnit in Eclipse but the test case is not running and the holly console not showing anything. The only line appears in console is :
<terminated>AccountManagmentModuleTest[JUnit] D:\Program Files\Java\jdk1.6.0_26\bin\javaw.exe(Nov 23, 2012 12:08:49 PM)
All I want to do is run the test case. Some lines are executing, like starting to connect to db, but no connection object created using DriverManager, also don't throw any exception.
enter code here
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = DriverManager.getConnection("jdbc:oracle:oci8:@local ip:1521:orcl", "dipak1","dipak1"); //got to finally from here, not even catching anything!!!
cstmt = conn.prepareCall(query);
cstmt.execute();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != conn) {
if (null != cstmt) {
cstmt.close();
}
conn.close();
}
}
Upvotes: 0
Views: 4553
Reputation: 231
When you doing Unit testing with Junit, you should not use try and catch block use throws Exception. Instead of if (null != conn) use JUnit assertion testing (assertNotNull or assertEquals or another one). To run the JUNit test on Eclipse :
On the panel JUnit you can see the unit testing result is succes or failed.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@Test
public void testDbConnexion() throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = DriverManager.getConnection("jdbc:oracle:oci8:@local ip:1521:orcl", "dipak1","dipak1"); //got to finally from here, not even catching anything!!!
cstmt = conn.prepareCall(query);
cstmt.execute();
assertNotNull(conn);
assertNotNull(cstmt);
connn.close();
}
Upvotes: 1
Reputation: 69329
It sounds like your test is executing but not producing the outputs you expect. Ensure you have the JUnit view open:
Window > Show View > Other... > Java > JUnit
This view will show you visually how many tests have run and how many have passed. If the tests are failing, you can right-click on the failed tests and debug them. You can also see the exceptions that have occurred.
The Console window won't show you any output from your JUnit tests unless you've including output statements in your test (either through a logging framework or simple println
statements). Only the JUnit view will show you whether your tests passed.
Upvotes: 2