If the question truly is:
How do I skip a section of code when unittesting in java
then I agree with the answers given. Dependency injection, mocking frameworks are absolutely the right way to go to do true unit testing.
However if the question is:
How do I skip a section of code when using JUnit (or other unit testing framework)
Then I think the answer is "it depends". Sometimes I use JUnit for integration testing - snippets of client code that I run against a test server to save me the trouble of doing these client side tests manually via a GUI. In this case I use system properties for example in my base class I have:
protected boolean skipTest()
{
String port = System.getProperty("jersey.test.port");
// don't run this test unless developer has explicitly set the testing properties
// this is an integration test, not a unit test
return port == null;
}
Then in the actual test class it looks like this:
// verify a successful login
@Test
public void testLogin()
{
if (skipTest())
return;
// do real test
So, my thought is if you really cannot refactor the Oracle stuff out of your DAO, then you really are doing an integration test and it's OK to have a skipTest in your unit test.