junit4

Junit SuiteClasses with a static list of classes

这一生的挚爱 提交于 2019-11-29 10:45:01
SuiteClasses will work just fine with a list of classes like {Test1.class,Test2.class} , but when I try to generate a static list of classes, it says incompatible types: required java.lang.Class<?> but found java.lang.Class<?>[] What am I missing? @RunWith(Suite.class) @Suite.SuiteClasses(TestSuite.classes) public class TestSuite { public static Class<?> [] classes; static { classes = new Class<?> [1]; classes[0] = MyTest.class; } } That shouldn't really work. You are intended to put the array within the annotation as a constant. Even if you got past this problem, the compiler would reject it.

Where should the integration tests be stored when using the maven-failsafe-plugin?

非 Y 不嫁゛ 提交于 2019-11-29 10:16:49
Do I have to place my integration tests under src/test with the rest of my unit tests and just distinguish them by a pattern such as *Integr*Test , *ITTest , or can they be in src/it (as is the case when developing Maven plugins and using the maven-invoker-plugin )? I'm asking this because, to me it looks not clean enough if both unit and integration tests are in the same place, (even if they were to be controlled via a Maven profile). First maven-fails-plugin runs by default in another life cycle phase (integration-test) as maven-surefire-plugin (test) does. Furthermore you can configurate

Upgrading to JUnit4 and keeping legacy JUnit 3 tests and test suites by running them together

别来无恙 提交于 2019-11-29 08:39:20
问题 I was surprised not to find the answer so far. If I am missing something basic I will be more than happy to know that. There is a large legacy code base that was upgraded to Java 6 (from 1.4). Large number of JUnit 3 tests are present in the code and are organized into test suite that runs successfully with JUnit 4 default runner in Eclipse. Now, I am adding new tests that are pure JUnit 4 tests (annotations, no TestCase, etc.). What would be a way of running both old JUnit 3 test suite and

Create my own MethodSorter for junit's @FixMethodOrder

試著忘記壹切 提交于 2019-11-29 07:19:17
junit 4.11 comes with the @FixMethodOrder -annotation, which makes it possible to select a MethodSorter-implementation to order the junit tests. There are three default sorters, JVM , NAME_ASCENDING and DEFAULT . Now, I would like to create my own MethodSorter. Can anyone help me with any pointers to how to do that? Short Answer This isn't easy, and is discouraged, because JUnit doesn't encourage dependent tests. Long Answer For more information, see extended discussion on SortMethodsWith allows the user to choose the order of execution of the methods within a test class . JUnit doesn't

Getting javassist.NotFoundException with PowerMock and PowerRule in JUnit with Mockito

China☆狼群 提交于 2019-11-29 07:04:17
I have integrated PowerMock and PowerRule in JUnit with Mockito. Here are my dependencies: <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.12.0.GA</version> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>org.powermoc</groupId> <artifactId>powermock-module-junit4</artifactId> <version>1.4.12</version> <scope>test</scope> </dependency> <dependency> <groupId

Java unit test for different input data

被刻印的时光 ゝ 提交于 2019-11-29 04:08:20
I need to test some api. For example I have multiple @Test methods in the class to test my functionality, before init I connect to some url of my service, and use it. If I have my service at multiple urls(different server environments), how can I Test this functionality for different service urls? Flow: Init conncetion by url Run all Tests Init conncetion by another url Run all Tests(the same) ... when was only one host I do like this: public class TestAPI{ @org.junit.Before public void init() { service = new Service("www.test.com"); } @org.junit.Test public void testA(){ service.CallA(); }

Running each JUnit test in a separate JVM in Eclipse?

谁都会走 提交于 2019-11-29 03:44:16
I have a project with nearly 500 individual tests in around 200 test classes. Some of these tests don't do a great job of tearing down their own state after they're finished, and in Eclipse this results in some tests failing. The tests all pass when running the test suite from the command line via Ant. Can I enable 'test isolation' somehow in Eclipse? I don't mind if it takes longer to run. Long term, I will clean up the misbehaving tests, but in the short term I'd like to get the tests working. If you use Ant in Eclipse, you can set the JUnit task to fork a new JVM process for each test,

JUnit right way of test expected exceptions

杀马特。学长 韩版系。学妹 提交于 2019-11-29 03:31:35
Hello guys I was wondering if this way of testing my exception is ok, i have this exception i need to throw in the second test annotation, im receiving as result a red evil bar, and a succeed and a failure, as you can guess the failure is my concern, i have a fail(); there but the reason is because i read thats the way to test the exception and now im confused. Also i have to say im willin get the green bar because im expecting the exception, but i dont know if failure is the right way to see the answer of the expected exception. Also if you had any advice, I would appreciate it @Before public

Can I avoid running junit tests twice in eclipse when using a TestSuite?

ⅰ亾dé卋堺 提交于 2019-11-29 03:19:44
I need to do some per-suite initialisation (starting a web-server). It is working fine except that when I run all tests in my project in eclipse my tests run twice. My test suite looks a bit like this: @RunWith(Suite.class) @Suite.SuiteClasses({ SubtestOne.class, SubtestTwo.class }) public class TestSuite { [...] } public class SubtestOne { @Test public void testOne() { [...] } } public class SubtestTwo { @Test public void testTwo() { [...] } } When I run all test in project in eclipse this causes the junit plugin to run the tests twice like this: SubtestOne SubtestTwo TestSuite SubtestOne

Spring JUnit Test Error

佐手、 提交于 2019-11-29 02:49:59
I am receiving the following error when I attempt to run my Spring JUnit test. I am just trying to get familiar with creating JUnits using the Spring Framework. JUnit Class: package org.xxx.springdao.mongo_datadictionary; import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.xxx.springdao.mongo