junit

How do I get my Spring-JUnit test to think its running in a GenericApplicationContext?

99封情书 提交于 2019-12-19 05:47:32
问题 I’m using Spring 3.2.6.RELEASE , JUnit 4.11 , and DWR 3.0.0-rc2 . My question is, when running a Spring-JUnit integration test, how can I simulate things being run in a org.springframework.context.support.GenericApplicationContext ? I tried this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-context.xml", "classpath:dwr-context.xml" }) @WebAppConfiguration public class MyServiceIT {} in which my “dwr-context.xml” file is set to be <?xml version="1.0" encoding

How do I get my Spring-JUnit test to think its running in a GenericApplicationContext?

萝らか妹 提交于 2019-12-19 05:47:20
问题 I’m using Spring 3.2.6.RELEASE , JUnit 4.11 , and DWR 3.0.0-rc2 . My question is, when running a Spring-JUnit integration test, how can I simulate things being run in a org.springframework.context.support.GenericApplicationContext ? I tried this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-context.xml", "classpath:dwr-context.xml" }) @WebAppConfiguration public class MyServiceIT {} in which my “dwr-context.xml” file is set to be <?xml version="1.0" encoding

Test run failed: Test run failed to complete. Expected 1 tests, received 0

徘徊边缘 提交于 2019-12-19 05:22:08
问题 I tried starting a JUnit test (robotium) for my app: public class MainTest extends ActivityInstrumentationTestCase2<MainActivity> { private Solo solo; public MainTest() { super("nix.android.contact", MainActivity.class);// TODO Auto-generated constructor stub } protected void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); } public void AddContact() { solo.assertCurrentActivity("main", MainActivity.class); } } Manifest <instrumentation android

How do I mock a TransactionManager in a JUnit test, (outside of the container)?

隐身守侯 提交于 2019-12-19 05:15:54
问题 I'm using Spring 3.1.0.RELEASE, JUnit 4.8.1, and ultimately deploying my application to a JBoss 4.2 server (I know, I know). As part of setting up my unit test, I have this in my Spring test application context ... <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransactionName"> <value>UserTransaction</value> </property> </bean> Of course, right now this fails because there is nothing bound to the JNDI name,

Testing main method by junit [duplicate]

爷,独闯天下 提交于 2019-12-19 05:06:17
问题 This question already has answers here : Using JUnit to test a main method that requires simulation of keyboard input with an input stream? (2 answers) JUnit test for System.out.println() (12 answers) Closed 3 years ago . I wrote a class which takes input from console and arguments in main method. The main method calls different methods for different console inputs and it calls different function for different arguments. So i want to test this main method with Junit by mimicking these inputs

gradle compileJava error: package org.junit does not exist

☆樱花仙子☆ 提交于 2019-12-19 05:06:11
问题 I'm trying to implement a simple junit test using gradle and running into the following issue when I run gradle test : :compileJava /Users/wogsland/Projects/gradling/src/test/CalculatorTest.java:1: error: package org.junit does not exist import static org.junit.Assert.assertEquals; ^ /Users/wogsland/Projects/gradling/src/test/CalculatorTest.java:1: error: static import only from classes and interfaces import static org.junit.Assert.assertEquals; ^ /Users/wogsland/Projects/gradling/src/test

Why does heap space run out only when running JUnit tests?

假如想象 提交于 2019-12-19 05:05:14
问题 When running JUnit tests, I always seem to run into this error: eclipse outOfMemoryError: heap space I have monitored Eclipse with JConsole and heap memory peaks at about 150MB. I have set heap memory to 1GB. I am using the following arguments when starting Eclipse: -vm "C:\Program Files\Java\jre1.5.0_08\bin\javaw.exe" -vmargs -Xmx1024M -XX:MaxPermSize=128M -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false Does

Why does heap space run out only when running JUnit tests?

我的未来我决定 提交于 2019-12-19 05:04:51
问题 When running JUnit tests, I always seem to run into this error: eclipse outOfMemoryError: heap space I have monitored Eclipse with JConsole and heap memory peaks at about 150MB. I have set heap memory to 1GB. I am using the following arguments when starting Eclipse: -vm "C:\Program Files\Java\jre1.5.0_08\bin\javaw.exe" -vmargs -Xmx1024M -XX:MaxPermSize=128M -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false Does

User Mockito to unit test a function doing async task in my case

℡╲_俬逩灬. 提交于 2019-12-19 04:57:09
问题 In my Android project, I have a class extends HandlerThread: public class MyHandlerThread extends HandlerThreads { private Handler mHandler; … public void doAsyncTask(MyAsyncTask task) { mHandler = new Handler(this.getLooper()); mHandler.post(task); } } The above function's parameter type MyAsyncTask is a class extends Runnable : public abstract class MyAsyncTask implements Runnable { @Override public void run() { doTask(); } public abstract void doTask(); } I have a MyWorker class which has

Mock private static final variables in the testing class

我的未来我决定 提交于 2019-12-19 04:48:06
问题 I have a few private static final fields in the class I want to test. Like follows public class ClassToTest{ .... private static final Myclass myclass = MyClassFactory.getMyClass(type.firstType); .... } The type is a enum in the MyClassFactory. That factory do is it initialize object according to type passed and return. My question is does powermock support this and if so how to do this. 回答1: You can use reflection also if any mock library works for you. Field f = classToTest.getclass()