0

I have the following code:

@Override
public long getUniqueId() {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String dateAndTime= dateFormat.format(new Date());
    jdbcTemplate.update(someSqlQuery, dateAndTime);

    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("IDENTITY").withReturnValue();
    }
    return 0;
}

And I want to write simple unit test but whenever the code reaches the line with SimpleJdbcCall throws exception that "DataSource is not specified". This is my test so far:

@Test
public void testGetBatchId() {
    transactionImpl.getUniqueId();
}

What is wrong with my setup?

2
  • 1
    That's not a unit test, it's an integration test. Also, is your data source defined in the test scope? Commented Sep 5, 2016 at 10:33
  • There appears to be an extra '}' in your "following code" section. Is there some code missing from the code you would like to test? Commented Sep 5, 2016 at 12:47

1 Answer 1

1

If you want to make integration test you need the data source defined in the test scope

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = GatewayApplication.class)
@WebAppConfiguration
@Transactional
public class ControllerIT {
Sign up to request clarification or add additional context in comments.

6 Comments

I am using spring boot by the way :)
In that case, did you use @RunWith(SpringRunner.class) and @SpringBootTest ?
Only @RunWith(SpringJUnit4ClassRunner.class) Not @SpringBootTest
I am using my own extension of the Application class if that is what you mean?
Does your test know that? Have you given a reference to this in an annotation at the test? Hard to guess, without your actuall test class ;-)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.