junit4

How can I test exception in completable future?

拈花ヽ惹草 提交于 2019-12-10 05:43:43
问题 I have been converting some code to be asynchronous. The original unit test used the annotation @Test(expected = MyExcpetion.class) but I don't think this will work because the exception I want to assert on is wrapped in java.util.concurrent.ExcutionException . I did try calling my future like this but my assertion is still failing and I don't love that I had to add in return null myApiCall.get(123).exceptionally((ex) -> { assertEquals(ex.getCause(),MyCustomException.class) return null } I

Spring JUnit4 manual-/auto-wiring dilemma

给你一囗甜甜゛ 提交于 2019-12-10 05:24:34
问题 I ran into an issue that can only be explained with my fundamental lack of understanding of Spring's IoC container facilities and context setup, so I would ask for clarification regarding this. Just for reference, an application I am maintaing has the following stack of technologies: Java 1.6 Spring 2.5.6 RichFaces 3.3.1-GA UI Spring framework is used for bean management with Spring JDBC module used for DAO support Maven is used as build manager JUnit 4.4 is now introduced as test engine I am

Resources$NotFoundException when calling Robolectric.buildActivity()

风格不统一 提交于 2019-12-10 04:04:50
问题 I am using Robolectric 3.0 RC3 for unit testing in Android Studio. And I am getting a ResourceNotFoundException every time I run the test. Please help me resolve the issue. build.gradle dependencies { testCompile 'junit:junit:4.12' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.0' testCompile 'org.mockito:mockito-core:1.9.5' testCompile 'org.robolectric:robolectric:3.0-rc3' compile 'com.ibm.icu:icu4j:53.1' } Test Class @Before public void

Spring Boot Application not reading application.properties file when using Maven test

旧城冷巷雨未停 提交于 2019-12-10 00:38:22
问题 UPDATE: I realized a couple of things now. My application.properties file is being loaded properly because I verified via the /env path (thanks Dave) that my DB properties are being loaded. The problem appears to be that when I run it using the Spring Boot maven plug-in,it fails to initialize my dataSource. mvn spring-boot:run This then causes my application to blow-up with errors because other beans can't get initialized. The odd thing is it runs fine from Eclipse. I have a class called

Robolectric+Eclipse Can't find resources?

心不动则不痛 提交于 2019-12-09 16:33:38
问题 I just configured a test project for my Android app to use Robolectric. I followed the Eclipse Quick Start. An exception is raised executing my simple very first test. java.lang.RuntimeException: java.lang.NullPointerException at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:93) at com.xtremelabs.robolectric.res.ResourceLoader.getStringValue(ResourceLoader.java:271) at com.xtremelabs.robolectric.shadows.ShadowResources.getString(ShadowResources.java:56) at android

How to get Junit 4 to ignore a Base Test Class?

十年热恋 提交于 2019-12-09 14:00:38
问题 I have a base class for many tests that has some helper methods they all need. It does not by itself have any tests on it, but JUnit (in eclipse) is invoking the test runner on it and complaining that there are no methods to test. How can I make it ignore this class? I know I could add a dummyTest method that would solve the problem, but it would also appear for all the children classes. Suggestions? 回答1: Use to @Ignore annotation. It also works on classes. See this one: @Ignore public class

Struts 2 JUnit Plugin v2.2.3: Test Class Extending StrutsTestCase; 'request' is null

帅比萌擦擦* 提交于 2019-12-09 13:54:57
问题 I am attempting to use the Struts2 JUnit Plugin (v2.2.3 w/ Struts2 v2.2.3) and have run into several issues. I attempted to use the Struts2 JUnit Plugin Tutorial as a guide. The first change I needed to make (not in the guide) is to annotate my test class with: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath*:applicationContext-test.xml"}) because I was getting the error when trying to run my unit test: SEVERE: [56:51.239] ********** FATAL ERROR STARTING UP

Bad type on the operand stack in arraylength

五迷三道 提交于 2019-12-09 08:08:55
问题 I am trying to test a method using powermock. i haven't written any test cases yet. Just trying to set up the class for Mocking. here is what I have so far: @RunWith(PowerMockRunner.class) @PrepareForTest({ ReadRubric.class }) public class ReadRubricTest { @Before public void setUp() throws Exception { PowerMockito.mock(ReadRubric.class); } @After public void tearDown() throws Exception { } @Test public void invalidFile() throws Exception { } } When I try to run this test I get the following

Exclude individual JUnit Test methods without modifying the Test class?

∥☆過路亽.° 提交于 2019-12-09 03:07:51
问题 I'm currently re-using JUnit 4 tests from another project against my code. I obtain them directly from the other project's repository as part of my automated Ant build. This is great, as it ensures I keep my code green against the very latest version of the tests. However, there is a subset of tests that I never expect to pass on my code. But if I start adding @Ignore annotations to those tests, I will have to maintain my own separate copy of the test implementation, which I really don't want

@parameters method is executed before @beforeclass method

∥☆過路亽.° 提交于 2019-12-09 02:51:17
问题 I'm using "parametrized" feature of junit 4 and I noticed that @parameters method is executed before @beforeclass method. This is creating a problem for me because the parameters i'm passing to the test cases via @parameters depends on the code initialize in the @beforeclass method. For example @RunWith(Parameterized.class) public class TestOtherClass { String argument; private static boolean initializeThis; public TestOtherClass(String parameter) throws Exception { argument=parameter; }