Reputation: 11524
I am currently writing junit tests for my program.
One of my tests updated an existing product. Here`s the code:
@Test
public void testUpdate(){
Produkt p = new Produkt(1, "apple", "food", true, 2.00, false, true);
assertFalse(handler.updateProdukt(p)==0);;
}
but eclispe always says:
The operator == is undefined for the argument type(s) void, int
if I write null nothing changes...
Is there a possibility to test whether the updatedProdukt is null or not?
I really appreaciate your answer!!!
Upvotes: 0
Views: 353
Reputation: 228
Try following code if returns int or Strings or Long value.
assertFalse(handler.updateProdukt(p).equals(0));
Upvotes: 0
Reputation: 6475
What does your updateProdukt()
return? Isn't is returning void?
You need to return something from updateProdukt() to be able to use == operator.
Upvotes: 0
Reputation: 159754
Its more than like that
handler.updateProdukt(p)
does not return any value, you need to change the signature to
int handler.updateProdukt(p)
Upvotes: 1
Reputation: 262464
Your method is void
. It returns nothing and thus the return value cannot be used in assignments or expressions.
Has nothing to do with jUnit or Eclipse.
Maybe you want something like this:
handler.updateProdukt(p);
assertEquals("has been updated", theNewExpectedValue, p.getSomeValue());
Upvotes: 3
Reputation: 274522
It's because your updateProdukt
method returns void. Change it to return something e.g. a boolean
or an int
, then you can use it in an assert
.
The question is: what is updateProdukt
doing and what do you wish to test? If it is updating the specified product then you should return a boolean
(true or false) to indicate whether the specified product was updated successfully. Alternatively, return the Product
which was updated or null if no product was updated.
Upvotes: 0