Skip to content
Advertisement

Tag: junit

Testing Private method using mockito

How to test private method is called or not, and how to test private method using mockito? Answer You can’t do that with Mockito but you can use Powermock to extend Mockito and mock private methods. Powermock supports Mockito. Here’s an example.

Guice injector in JUnit tests [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago. Improve this question Using Guice, is it a good practice to get a new injector in each JUnit test class, as each test class

Ignore Assertion failure in a testcase (JUnit)

Currently, I am writing the automation testing using java and selenium rc. I would like to verify all the contents present on the user interface, the function is ie below: The function is supposed to return a String containing information about the testing. However, the function stopped once an assertion error happened. Is there a way to ignore the failure

Loop through array, each element a JUnit test

I have a JUnit 4 test that loops through an array of test data: Because it’s all in one test method, the whole test stops as soon as one element in the array fails. Is there a way around that, without making a method for each test item? Maybe something with reflection? Answer Use JUnit 4’s parameterized tests. They are

Comparing arrays in JUnit assertions, concise built-in way?

Is there a concise, built-in way to do equals assertions on two like-typed arrays in JUnit? By default (at least in JUnit 4) it seems to do an instance compare on the array object itself. EG, doesn’t work: Of course, I can do it manually with: ..but is there a better way? Answer Use org.junit.Assert’s method assertArrayEquals: If this method

HowTo Unit Test Client Server Code

I’m currently writing a Java Client Server Application. So i want to implement two Libraries, one for the Client and one for the Server. The Client Server Communication has a very strict protocol, that I wan’t to test with JUnit. As build tool im using Maven and a Husdon Server for continues Integration. Actually I do not have any good

Bringing unit testing to an existing project

I’m working on an existing Java EE project with various maven modules that are developed in Eclipse, bundled together and deployed on JBoss using Java 1.6. I have the opportunity to prepare any framework and document how unit testing should be brought to the project. Can you offer any advice on… JUnit is where I expect to start, is this

Advertisement