HJW
HJW

Reputation: 23443

How to unit test an entity is targeting the correct DBMS table

I have the following entity and it was not until run time that i realized that the table name annotation is incorrect.

How can i write unit tests to prevent this?

@Entity
@Table(name = "cache_server")
public class VirtualMachine implements Serializable {
}

Upvotes: 2

Views: 73

Answers (1)

V G
V G

Reputation: 19002

It is not about unit testing here, but rather about integration testing, as you need a JPA provider to test it (with a DB server). And when it comes to integration tests, it is very specific to what technologies you use. If you are in Application Server, like Jboss, take a look at Arquillian.

UPDATE

Although I think that usually you do not want to unit test values in annotations, as they represent configuration data, you can always read the values in the annotations using some reflexion. See this question (directly in the question) for an example.

Upvotes: 1

Related Questions