Skip to content

Tag: junit

How do I compare Integer and Long types with Junit?

How do I compare Integer and Long types with Junit ? The result of assertThat(poiList.get(0).get(“id_pk”)).isEqualTo(member.getId_pk()); is: The two types are: How can I compare 1 and 1L to be equal? best regards Answer You can convert Integer to Long via java.lang.Integer#longValue: BUT beware of…

JUnit 5 and Test Suites

We have a pure JUnit-5 project and we want to categories our unit tests. To do so, what I understand is we need to include the JUnit-4 @RunWith(JUnitPlatform.class). In Intellij-Idea I can run all or just test suites without problems but I get an error on the execution with maven: in Intellij-Idea some test c…

How to get dynamic numbers using xpath?

How do I get dynamically changing numbers in the span block ? Method: I can’t figure out how to do this. My method xpatch which returns the value: How can I get dynamically changing numbers in such blocks for further comparison? Answer byRaetUSD is a webelement you should call getText to get the text or…

Mockito How to mock and assert a thrown exception

I have this junit: but I have this error: I also tried: Answer The problem is that you are stubbing, but not really testing anything. And if you are not testing anything, then there is no need for stubbing. That’s why you have unnecessary Mockito stubbings. I assume that you want to test your SecurityMa…

junit- sonarQube test coverage : if condition

can you help me how I can cover if statement by junit test in this method: This is my Method in the controller “User” : My problem is with the 2 lines of the if statment, I don’t know how i want to cover them. This is my test code for this method : Thank you in advance for your