Java Reference
In-Depth Information
base. And, of course, we also have to add the empty beans.xml file in order to enable
the CDI.
Finally, we inject the service we would like to test (yes, it's possible to inject services to
test classes) and add one test method:
@Inject
TicketService ticketService;
@Test
public void shouldCreateSeatType() throws Exception {
// given
final SeatType seatType = new SeatType();
seatType.setDescription("Balcony");
seatType.setPrice(11);
seatType.setQuantity(5);
// when
ticketService.createSeatType(seatType);
// then
assertNotNull(seatType.getId());
}
Here, the shouldCreateSeatType method will create a new SeatType attribute
using the createSeatType method from the TicketService class. Note how we
inject TicketService just as we would if we were running this code on the server
side.
Our first test case is now ready. We will just need to add an Arquillian configuration file
named arquillian.xml in our project, under src/test/resources :
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/
arquillian
http://jboss.org/schema/arquillian/
Search WWH ::




Custom Search