junit

Maven exclusion not working

无人久伴 提交于 2019-12-24 13:29:29
问题 I am working on a project that has a dependency of JUnit 4.11 and a transitive dependency of JMock 2.6.0-RC2 who in turn has a dependency of JUnit-dep 4.4 . This transitive dependency of JUnit-dep is overriding the setting in my local pom for JUnit . By overriding, I mean that when I call a JUnit method, it calls the one from v4.4 as opposed to v4.11. Adding exclusions for JMock and for JUnit-dep had no effect on my resolved dependencies. Note: JUnit and JUnit-dep have separate artifactId s,

Get Maven basedir from a properties file in a SpringBoot project

喜夏-厌秋 提交于 2019-12-24 12:58:25
问题 The Maven project I inherited has some resource files used in JUnits. Those files are referred in a properties file as absolute paths. Let's assume the Maven project is under myproject , where the main pom.xml resides. A config.properties file has: keystore.file=C:/Users/tom/myproject/web/src/test/resources/myfile.jks I want to refer to that resource from a relative path of the Maven project. So I have been trying something like: keystore.file=${project.basedir}/web/src/test/resources/myfile

UISpec4J Capturing modal dialog, before the trigger finish

本小妞迷上赌 提交于 2019-12-24 12:35:13
问题 I have some code where I'm showing up a dialog with two textboxes and two buttons (as OK, and Cancel, typical login window). The execution of the main code after the ".setVisible(true)" is conditioned to the values entered on that modal window. The problem that I'm facing now is that if I do something like this: WindowInterceptor.init(new Trigger() { @Override public void run() throws Exception { LoginModal loginWin=new LoginModal(); loginWin.setVisible(true); if(loginWin.getPassword().equals

Mockito: Zero interactions with this mock

廉价感情. 提交于 2019-12-24 12:34:09
问题 I have a class that I would like to test. @Configuration @Import(EmailageConfiguration.class) public class EmailageServiceConfiguration { private static final String EMAILAGE_ACCOUNT_ID_CONFIG_KEY = "emailage.key"; private static final String EMAILAGE_API_KEY_CONFIG_KEY = "emailage.secret"; @Bean public EmailageConfigHolder emailageConfigHolder(Environment env) { final EmailageConfigHolder holder = new EmailageConfigHolder(); holder.setApiKey(env.getRequiredProperty(EMAILAGE_API_KEY_CONFIG

Powermock constructor mocking has no effect on the instantiated object

有些话、适合烂在心里 提交于 2019-12-24 11:47:10
问题 Class A{ B objB = new B(); objB.someBMethod(); } Class B{ public void someBMethof(){ C objC = new C(); } } class C{ int a=1; public C(){} public C(int v){ a=v; } } @RunWith( PoswerMockRunner.class ) @PrepareForTest({ A.class, B.class, C.class}) Class TestApp{ @Mock C mockC; PowerMockito.whenNew( C.class ).withNoArguments().thenReturn(mockC); } The above code captures what im trying to do. But the whenNew() does not seem to be working and when i try debuggin the C object created is not the

Play 2.5.x junit test error handling with fakeRequest

本秂侑毒 提交于 2019-12-24 10:58:54
问题 My program uses global error handling. When i using fakeRequest() to test, it throws out exception instead of trigger my error handler. Am I missing some configuration? Or how can I test my global error handler. Below is my current code: Controller: public class MyController { public Result MyService() { if (true) throw new RuntimeException("exception"); } } ErrorHandler: @Singleton public class MyErrorHandler extends DefaultHttpErrorHandler { @Inject public MyErrorHandler (Configuration

Junit: changing sequence of test running

冷暖自知 提交于 2019-12-24 10:58:22
问题 I have a big mess with 100 tests in one class and running all of them by clicking "Test project (...). They run in a random order and I would like them to run in a specific order - from beginning to the end, the same order that I wrote them. In eclipse it's not a problem because eclipse just works like that, how to do it in netbeans? Any help will be appreciated. Edit (due to answers): Tests order is required for the clearance of the log. They are independent. 回答1: If your tests needs to run

Need to run “maven package” to update unit tests

一曲冷凌霜 提交于 2019-12-24 10:24:04
问题 I recently "enabled dependency management" in maven2 for a web project which I had a simple test class running in. Before I added the maven2 management, whenever I updated the test - the change would appear instantaneous. However, now I have to run "mvn clean package" before the slightest change can be picked up. I can see "Maven Builder: AUTO_BUILD" run whenever I save a class but the update just isn't picked up until I run the mvn goal. I also can't seem to configure a "Maven Builder" when

Unit test android application with rxjava

∥☆過路亽.° 提交于 2019-12-24 10:21:28
问题 I recently jumped in Android Unit testing and I'm still struggling in writing my unit tests. I'm trying to test my Presenter, specifically a method that returns a list of repositories from Github Api, but I keep getting a Null Pointer Exception and I don't understand why. RepositoriesPresenter method I want to unit test: public void presenterLoadRepos(boolean onlineRequired, String owner) { // Clear old data on view view.clearRepos(); //recovering access token data from Shared Preferences

Custom AppenderBase not being called

纵然是瞬间 提交于 2019-12-24 10:06:53
问题 I am writing a custom AppenderBase for my test and configuring it in logback-test.xml The append() function however is not being called. import ch.qos.logback.core.AppenderBase; import org.apache.log4j.spi.LoggingEvent; import java.util.ArrayList; import java.util.List; public class TestAppender extends AppenderBase<LoggingEvent> { public static List<LoggingEvent> events = new ArrayList<>(); @Override protected void append(LoggingEvent e) { events.add(e); } } This is my configuration file :