Skip to content
Advertisement

org.springframework.dao.DataIntegrityViolationException While running Junit testcase in sprintboot

Have developed a springboot project and Using H2 database in writing testcases, if we run individual controllerTest class , All testcases are passing. but we run all the test classes together few test classes are failing with below error:

JavaScript

Using following annotations for each controllertest class:

JavaScript

H2 database configs used in application-test.properties file are:

JavaScript

Advertisement

Answer

The problem seems to be that you have two entities with a relation and try to delete one of them as the problem says:

Referential integrity constraint violation: "FK3YM8KNF15YHIGFNBABIYLPY1C: PUBLIC.USER_OTP_DATA FOREIGN KEY(CUSTOMER_ID) REFERENCES PUBLIC.USERS(CUSTOMER_ID) (1)"; SQL statement:

There either is an automated SQL statement being executed or one of your methods does as the very top of the stacktrace says:

org.springframework.dao.DataIntegrityViolationException: could not execute statement

And a bit further, there is a reference to your code:

JavaScript

Hope this already helps. Otherwise, please also provide the code from the method testGetListOfUserByCustomeridNotFound

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement