I am attempting to run a JUnit Test from a Java Class with:
JUnitCore core = new JUnitCore();
core.addListener(new RunListener());
core.run(classToRun);
Problem is my JUnit test requires a database connection that is currently hardcoded in the JUnit test itself.
What I am looking for is a way to run the JUnit test programmatically(above) but pass a database connection to it that I create in my Java Class that runs the test, and not hardcoded within the JUnit class.
Basically something like
JUnitCore core = new JUnitCore();
core.addListener(new RunListener());
core.addParameters(java.sql.Connection);
core.run(classToRun);
Then within the classToRun:
@Test
Public void Test1(Connection dbConnection){
Statement st = dbConnection.createStatement();
ResultSet rs = st.executeQuery("select total from dual");
rs.next();
String myTotal = rs.getString("TOTAL");
//btw my tests are selenium testcases:)
selenium.isTextPresent(myTotal);
}
I know about The @Parameters, but it doesn't seem applicable here as it is more for running the same test case multiple times with differing values. I want all of my test cases to share a database connection that I pass in through a configuration file to my java client that then runs those test cases (also passed in through the configuration file).
Is this possible?
P.S. I understand this seems like an odd way of doing things.