Skip to content
Advertisement

Tag: junit

Loading a native library in an Android JUnit test

I’ve generated a native library using ndk-build which I’m able to load and use with in my Android application. However, I want to write some tests against this part of my app. When calling the native function in my tests, I recieve this exception message: …where process is my native library to import, named libprocess.so. I’m using Roboelectric for my

Does Parameterized JUnit test correct with `mvn test`?

I’m just implemented a JUnit test case using JUnit 4.11 following the example: https://github.com/junit-team/junit/blob/master/doc/ReleaseNotes4.11.md#example-1 I create a maven project using And this test case: But when I test it using mvn test , maven said: How to make it work? Answer The problem is the naming convention of maven which is based on maven-surefire-plugin which needs a naming like Test.java,

Mocking a Spy method with Mockito

I am writing a unit test for a FizzConfigurator class that looks like: I’d like to write a simple unit test that stubs the doWidget(String,Config) method (so that it doesn’t actually fire and hit the database), but that allows me to verify that calling doBuzz(String) ends up executing doWidget. Mockito seems like the right tool for the job here. This

how to test Comparator at junit test

I need to test this method – compare(). Can You get advice? How better I can do this(all part if, else-if, else). After this recomendations – we have next picture (Thank YOU guys a lot!): All is normal testing now. Answer Just instantiate your comparator class and pass in objects:

Mock a constructor with parameter

I have a class as below: The logic in the constructor A(String test) and check() are the things I am trying to mock. I want any calls like: new A($$$any string$$$).check() returns a dummy string “test”. I tried: But it doesn’t seem to be working. new A($$$any string$$$).check() is still going through the constructor logic instead of fetch the mocked

Exclude individual test from ‘before’ method in JUnit

All tests in my test class execute a ‘before’ method (annotated with JUnit’s @Before) before the execution of each test. I need a particular test not to execute this before method. Is there a way to do it? Answer Unfortunately you have to code this logic. JUnit does not have such feature. Generally you have 2 solutions: Just separate test

AntBuilder can’t find package org.junit

I added some unit tests to a test directory (parallel to my src directory) in my project in Eclipse using the “JUnit test case” new file dialogue. I have two builders, the default Java Builder and an AntBuilder I added. The Java Builder continues to work, but the AntBuilder fails in Eclipse. When I select Project -> Build All, it

Mockito: Trying to spy on method is calling the original method

I’m using Mockito 1.9.0. I want mock the behaviour for a single method of a class in a JUnit test, so I have The problem is, in the second line, myClassSpy.method1() is actually getting called, resulting in an exception. The only reason I’m using mocks is so that later, whenever myClassSpy.method1() is called, the real method won’t be called and

JUnit: testing helper class with only static methods

I am testing a helper class with only static methods with JUnit4 and Cobertura. Testing methods was easy task and is done already. However, cobertura shows that the class is not covered by tests completely, as it is not instantiated anywhere. I don’t want to create an instance of this class (it is a helper class), so first solution is

Advertisement