junit

Mocking getClass method with PowerMockito

谁说胖子不能爱 提交于 2019-12-30 18:30:20
问题 I'd like to avoid mocking the getClass() method for a class but cannot seem to find any way around it. I'm trying to test a class that stores objects class types in a HashMap to a particular method to be used later. A brief example of this is: public class ClassToTest { /** Map that will be populated with objects during constructor */ private Map<Class<?>, Method> map = new HashMap<Class<?>, Method>(); ClassToTest() { /* Loop through methods in ClassToTest and if they return a boolean and

What java version is needed for JUnit 4.8

霸气de小男生 提交于 2019-12-30 17:39:54
问题 I am trying to run JUnit test with a 1.5 JRE, but get the error Message: java.lang.UnsupportedClassVersionError: Bad version number in .class file When I switch to JRE 1.6 (actually a JDK but that shouldn't matter, right?) everythings works fine. So the questions are: Do we really need Java 6 for the current JUnit version? what is the newest JUnit version, that works with Java 5? 回答1: A spot check of a few classes shows that the JUnit 4.8.2 jar file was compiled with java 5, or with the java

JMeter, JUnit and Spring Java configuration

一个人想着一个人 提交于 2019-12-30 17:24:36
问题 Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null pointer exceptions. I am using the Spring annotation @SpringJUnit4ClassRunner and @ContextConfiguration to configure the JUnit test (which works). The goal is to be able to write JUnit test cases that can be measured for performance using JMeter. 回答1

JMeter, JUnit and Spring Java configuration

馋奶兔 提交于 2019-12-30 17:24:24
问题 Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null pointer exceptions. I am using the Spring annotation @SpringJUnit4ClassRunner and @ContextConfiguration to configure the JUnit test (which works). The goal is to be able to write JUnit test cases that can be measured for performance using JMeter. 回答1

Spring测试框架springContextTest

我是研究僧i 提交于 2019-12-30 15:32:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> ssh版本:spring4.2/struts2.3/hibernate4;除了一些必要的jar包外,使用spring自带的测试框架,还要额外导入spring-test-4.2.2.jar。 junit使用的是junit4.7,相关测试代码如下: package TestContext; import java.util.List; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; import entity

Struts2 JUnit ActionContext objects

Deadly 提交于 2019-12-30 11:38:07
问题 Problem: Struts ActionContext is null during test Using Struts2 JUnit plugin I have the following test: public class MainActionIT extends StrutsJUnit4TestCase { @Test public void testAction() { Map<String, Object> application = new HashMap<String, Object>(); application.put("options","home"); ActionContext.getContext().put("application",application); ActionProxy proxy = getActionProxy("/home"); String result = proxy.execute(); } } The two related classes are as follows: public class

JUnit Eclipse plugin source-code?

帅比萌擦擦* 提交于 2019-12-30 08:26:08
问题 I'm looking into writing an Eclipse plugin for FlexUnit and was wondering where I could get the sources for the JUnit Eclipse plugin. I checked the JUnit sources at sourceforge but couldn't spot any code that looked like the plugin code. Any idea where this code is available? 回答1: You can find it on Eclipse's repository: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.pde.junit/ 回答2: There are now git mirrors of the CVS repositories: org.eclipse.jdt.junit: git://dev.eclipse.org/org

MockMVC how to test exception and response code in the same test case

依然范特西╮ 提交于 2019-12-30 07:56:21
问题 I want to assert that an exception is raised and that the server returns an 500 internal server error. To highlight the intent a code snippet is provided: thrown.expect(NestedServletException.class); this.mockMvc.perform(post("/account") .contentType(MediaType.APPLICATION_JSON) .content(requestString)) .andExpect(status().isInternalServerError()); Of course it dosen't matter if I write isInternalServerError or isOk . The test will pass regardless if an exception is thrown below the throw

How do I define an order to run junit tests in Intellij?

百般思念 提交于 2019-12-30 06:00:12
问题 I have a flaky junit test that only fails if I run all my tests. I think that one test is causing another test to fail, I want to prove it before I try to fix it. If I run all tests, it runs the "bad setup" then it runs the "test that fails after bad setup". It also runs a lot of irrelevant, slow tests in between. But if I use a pattern to only run these two, it runs "test that fails after bad setup" then "bad setup". As a result, both pass. How do I only run "bad setup" and "test that fails

Android Robotium NoClassDefFoundError

陌路散爱 提交于 2019-12-30 05:56:36
问题 I was just trying to use Robotium in an Android JUnit Test, but the Testing always fails with an error: java.lang.NoClassDefFoundError: com.jayway.android.robotium.solo.Solo thrown at solo = new Solo(getInstrumentation(), getActivity()); in the setUp() method: protected void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); } I read somewhere that this could be related to the Android SDK revision 17, but I cannot confirm this, as I first tried