|
From: KARR, D. <dk...@at...> - 2012-12-21 17:49:16
|
And you can tell this from the occurrence counts in the margin. It's getting to both if bodies.
This is one situation where the coloring provided by EclEmma is a little bit clearer. Instead of just using green and red, it uses yellow to color lines with branches where not all of the branches have been taken.
From: John W. Lewis [mailto:Joh...@sa...]
Sent: Friday, December 21, 2012 6:50 AM
To: Mark Schrijver; cob...@li...
Subject: Re: [Cobertura-devel] report says code block isn't tested incorrectly
It is complaining that you don't have a test when the type != BUY. The type would also have to not equal SELL because it would not get to the second if statement if it was equal to SELL. So, in other words you need a test where type != BUY and type != SELL.
From: Mark Schrijver [mailto:ra...@ra...]
Sent: Thursday, December 20, 2012 4:34 PM
To: cob...@li...<mailto:cob...@li...>
Subject: [Cobertura-devel] report says code block isn't tested incorrectly
Hello,
First off, great toolkit.
That said, I do have a question. I've got the whole instrumentation, test and report task setup done. All that works like a charm, and I get really nice reports. But in the report for one of my tested classes, it states a piece of code isn't tested. When I step through the testcase though, I can see that piece of code being hit.
Here's my Java method:
public void setOrder(Order order) {
if (order.getType() == Order.TYPE.SELL) {
sellOrders.put(order.getId(), order);
} else if (order.getType() == Order.TYPE.BUY) {
buyOrders.put(order.getId(), order);
}
}
And here's my test code:
@Test
public void testSetOrder() {
Market market = new Market(1L, "Apeldoorn");
Resource metalResource = new Resource(1L, "metal", "Metal", 5F, 5F);
assertEquals("Invalid number of SELL orders", new Integer(0), new Integer(market.
getSellOrders().size()));
assertEquals("Invalid number of buy orders", new Integer(0), new Integer(market.
getBuyOrders().size()));
market.setOrder(new Order(TYPE.SELL, 1L, 15, metalResource, 1.5F, 1L));
assertEquals("Invalid number of SELL orders", new Integer(1), new Integer(market.
getSellOrders().size()));
assertEquals("Invalid number of buy orders", new Integer(0), new Integer(market.
getBuyOrders().size()));
market.setOrder(new Order(TYPE.BUY, 2L, 15, metalResource, 1.5F, 1L));
assertEquals("Invalid number of BUY orders", new Integer(1), new Integer(market.
getSellOrders().size()));
assertEquals("Invalid number of buy orders", new Integer(1), new Integer(market.
getBuyOrders().size()));
}
As you can see, I call the setOrder both with an Order of type SELL and of type BUY. But the report on the setOrder method clearly states the second if statement is never covered by my test.
|