junit4

Mockito - Wanted but not invoked: Actually, there were zero interactions with this mock

天涯浪子 提交于 2019-12-12 16:05:15
问题 I know there are already at least two same questions asked, but I still can't figure out why I am getting the exception. I need to unit test this method: void setEyelet(final PdfWriter printPdf, final float posX, final float posY) { InputStream is = WithDefinitions.class.getResourceAsStream(RES_EYELET); //RES_EYELET is a pdf. PdfContentByte canvas = printPdf.getDirectContent(); PdfReader reader = new PdfReader(is); PdfImportedPage page = printPdf.getImportedPage(reader, 1); canvas.addTemplate

Using multiple @parameters for JUNIT4

不羁的心 提交于 2019-12-12 14:33:53
问题 I am trying to write parameterize test in JUNIT4 and I don't know how to make multiple parameters for instance : @parameter1 {1,2,3,4} @test1 run test using @parameter1 @parameter2 {3,55,66,77} @test2 run test using @parameters2 Could anyone provide me with a sample snippet, that would be greatly appreciated. thank you. 回答1: Looks like you could take advantage of the @Theories and @TestedOn. import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import

Run As JUnit not appearing in Eclipse - using JUnit4

巧了我就是萌 提交于 2019-12-12 12:25:03
问题 I'm trying to write JUnit4 tests for my web app, and they had been working fine previously. However, now when I try to run the tests by right clicking the class file -> Run As -> JUnit Test I don't see that option. I think it could be because a colleague committed some Eclipse settings/property files on accident that messed with mine. I'm using Eclipse Helios on a Mac running 10.6.X. I noticed that the icons on the test classes changed from the "filled" J to a "bubble" J and I'm not sure if

Using command line arguments or system properties from a Parameterized Junit test?

自作多情 提交于 2019-12-12 11:47:44
问题 I use this method to setup my parameterized data: @Parameterized.Parameters public static Collection<Object[]> getStories() { Collection<Object[]> allStories = new ArrayList<Object[]>() new File(SPEC_DIRECTORY).eachFileRecurse(FileType.FILES) { file -> if (file.getName().endsWith('.story')) { Object[] args = [file.getName(), file] allStories << args } } return allStories } I invoke the main test with gradle via gradle test , but I do not seem to be able to see system properties. If I use the

Executing Initialization Code only once for multiple test classes

倾然丶 夕夏残阳落幕 提交于 2019-12-12 11:35:50
问题 I am writing unit test cases for my code. I am using PowerMockito with Junit. I have written an initialization code which will take care of all the initialization stuff in my application. Below is the way my code is structured: Class ServiceInitializer{ public static isInitialized = Boolean.FALSE; public static void initialize(){ //Initilization Code Goes Here isInitialized = Boolean.TRUE; } } @RunWith(PowerMockRunner.class) class BaseTest{ @Before public void preTest(){ //some code } static{

Maven 2 Not Running Junit 4 Tests

拟墨画扇 提交于 2019-12-12 10:38:24
问题 I'm having an issue getting surefire to run Junit4 tests. This same issue was reported in https://stackoverflow.com/questions/2021771?sort=newest#sort-top but the solution there was to removed the offending dependency whose transitive dependency caused the inclusion of junit3. In my case the dependency is necessary. I'm trying to figure out how to exclude transitive dependencies to junit3 so it is not included in the surefire:test classpath. Below are my pom.xml and the output from "mvn -X

Cannot resolve symbol AndroidJUnit4

我是研究僧i 提交于 2019-12-12 10:35:31
问题 I'm trying to add loginfacebook for my app. But when I added a repository that is need in doing this. It caused an error. The AndroidJUnit4 cannot resolve now. ExampleInstrumentedTest.java package com.example.user.enyatravelbataan; import android.content.Context; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import static junit.framework.Assert.assertEquals; import static org.junit

Spring @ContextConfiguration

纵饮孤独 提交于 2019-12-12 08:30:07
问题 I am running the next test: import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/META-INF/spring/applicationContext.xml" }) public class FloorServiceTest { @Autowired private

Spring Test DBunit Warning

元气小坏坏 提交于 2019-12-12 08:22:59
问题 I am using spring-test-dbunit and I get a warning in my Unit tests with this message: Code: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/context.xml"}) @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class }) public class TestDB { @Autowired private ICourseService courseService; @Test @DatabaseSetup("sampleData.xml") public

Counting method invocations in Unit tests

淺唱寂寞╮ 提交于 2019-12-12 08:17:15
问题 What is the best way to count method invocations in a Unit Test. Do any of the testing frameworks allow that? 回答1: It sounds like you may want to be using the .expects(1) type methods that mock frameworks usually provide. Using mockito, if you were testing a List and wanted to verify that clear was called 3 times and add was called at least once with these parameter you do the following: List mock = mock(List.class); someCodeThatInteractsWithMock(); verify(mock, times(3)).clear(); verify(mock