junit

How can I inject a data source dependency into a RESTful web service with Jersey (Test Framework)?

不问归期 提交于 2019-12-21 04:30:38
问题 I'm building a RESTful web service using Jersey that relies on MongoDB for persistence. The web service itself connects to the default database, but for the unit tests, I would like to use a separate test database. I would populate this test database in setUp, run my tests, and then destroy it in tearDown. Normally, I would use dependency injection here to supply the data source to an entity manager that the service would use, but in this case the web service is running independent of the

Why EclEmma doesn't coverage code with tests with @RunWith(PowerMockRunner.class)

烂漫一生 提交于 2019-12-21 04:03:26
问题 I am using EclEmma with Eclipse to help me to know where is missing code tests in my project, but all tests with @RunWith(PowerMockRunner.class) are not called and thus not tested. I´m using JUnit 4.8.1 with Mockito. What could it be? 回答1: Its a known bug reported for both parties: http://code.google.com/p/powermock/issues/detail?id=402 https://github.com/jacoco/eclemma/issues/15#issuecomment-9565210 eCoberture seems however to provide correct coverage. The only problem, that it seems not to

Database cleanup after Junit tests

狂风中的少年 提交于 2019-12-21 03:59:05
问题 I have to test some Thrift services using Junit. When I run my tests as a Thrift client, the services modify the server database. I am unable to find a good solution which can clean up the database after each test is run. Cleanup is important especially because the IDs need to be unique which are currently read form an XML file. Now, I have to manually change the IDs after running tests, so that the next set of tests can run without throwing primary key violation in the database. If I can

Run JUnit automatically when building Eclipse project

∥☆過路亽.° 提交于 2019-12-21 03:58:19
问题 I want to run my unit tests automatically when I save my Eclipse project. The project is built automatically whenever I save a file, so I think this should be possible in some way. How do I do it? Is the only option really to get an ant script and change the project build to use the ant script with targets build and compile ? Update I will try 2 different approaches now: Running an additional builder for my project that executes the ant target test (I have an ant script anyway) ct-eclipse,

Unit test best practice when testing class that reads and writes to the filesystem

耗尽温柔 提交于 2019-12-21 03:52:08
问题 I have a class that does operations on file's on a disk. More exactly it traverses a directory, reads through all files with a given suffix and does some operations on the data and then outputs them to a new file. I'm a bit dubious as to how to design a unittest for this class. I'm thinking having the setup method create a temporary directory and temporary files in /tmp/somefolder, but I'm suspecting this is a bad idea for a couple of reasons(Developers using windows, file permissions etc).

Mocking private method of class under test using JMockit

青春壹個敷衍的年華 提交于 2019-12-21 03:47:17
问题 I want to mock private method of a class under test but method return false first two times when the method is called after that it should return false. Here is the code what I tried. This is the class which is being tested public class ClassToTest { public void methodToTest() { Integer integerInstance = new Integer(0); boolean returnValue= methodToMock(integerInstance); if(returnValue) { System.out.println("methodToMock returned true"); } else { System.out.println("methodToMock returned true

Using junit test to pass command line argument to Spring Boot application

[亡魂溺海] 提交于 2019-12-21 03:42:29
问题 I have a very basic Spring Boot application, which is expecting an argument from command line, and without it doesn't work. Here is the code. @SpringBootApplication public class Application implements CommandLineRunner { private static final Logger log = LoggerFactory.getLogger(Application.class); @Autowired private Reader reader; @Autowired private Writer writer; public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override public void run(String...

Intellij: Change JUnit Test Class template

风流意气都作罢 提交于 2019-12-21 03:38:27
问题 I would like to customize the JUnit Test class template however I cannot find it anywhere in settings. This guy has the same problem. I can't find anything in File Templates or Live Templates. I'm using Intellij 11. 回答1: This is now solved in the latest IntelliJ IDEA / Android Studio. Go to: Settings -Editor -File and Code Templates -Code (tab) -JUnit4 Test Class edit the code in the right window. 回答2: The link provided by CrazyCoder suggests that this is not directly possible but that I you

Mockito, JUnit, Hamcrest, Versioning

三世轮回 提交于 2019-12-21 03:20:19
问题 By default, the required version of Hamcrest for: JUnit 4.11 Hamcrest 1.3 Mockito-core 1.9.5 Hamcrest 1.1 There were not insiginifcant API changes between Hamcrest 1.1 and 1.3. Currently my test cases attempt to run JUnit 4.11 with Hamcrest 1.1, but I'm reasonably sure that this is a bad idea. For similar reasons, I suspect that trying to use Mockito-core 1.9.5 with Hamcrest 1.3 is also a bad idea. What to do? Use Hamcrest 1.1 with the latest JUnit and Mockito Use Hamcrest 1.3 with the latest

No Runnable methods Error From Base Test class

北城余情 提交于 2019-12-21 03:15:08
问题 I have a A few base test classes that setup common configurations for spring,logging,jndi etc using test execution listeners that are then inherited by subclasses. This is done so tests can just run code without having to worry about getting jndi and logging services in place before being able to run testing code. Using intellij and invoking "run all tests" from the project base, the IDE attempts to run the base test class as a unit test and gives me the "No runnable methods" error. I know I