junit

Run all JUnit tests indepentently in Eclipse, reloading Spring context each time

时间秒杀一切 提交于 2019-12-18 09:27:41
问题 Goal: Find a way in Eclipse to execute all the tests in a JUnit class which reloads the Spring context before each test, instead of just once. Scenario: I inherited DAO test suite that uses an HSQL in-memory database which gets initialized with some sample data on context load. While running the tests, I noticed if the whole class is executed, all the tests pass. But specific test methods fail when executed individually. Clearly, the tests are not independent and early tests are altering the

Properly set (system) properties in JUnit 5

元气小坏坏 提交于 2019-12-18 08:55:19
问题 We are using an approach similar to System Rules to handle (system) properties in our JUnit 4 tests. The main reason for this is to clean up the environment after each test, so that other tests do not inadvertently depend on possible side effects. Since JUnit 5 is released, I wonder if there is a "JUnit 5 way" of doing this? 回答1: You can use the extension API. You could create an annotation which defines your extension to a test method. import org.junit.jupiter.api.extension.ExtendWith;

How do I run JUnit tests during my Ant build script while omitting test classes from my resulting jar?

萝らか妹 提交于 2019-12-18 08:53:15
问题 I'm using the Hello World with Ant tutorial from the Ant manual to learn about Ant. The last part of the tutorial involves adding JUnit tests to the project. I've got everything working as described in the tutorial and am now going on to make some minor changes. One of the changes I would like to make is to run the tests during a typical build but not have the *Test.class files end up in the final .jar file for the application. This is because the eventual project I will be working on will be

How do I run JUnit tests during my Ant build script while omitting test classes from my resulting jar?

巧了我就是萌 提交于 2019-12-18 08:51:41
问题 I'm using the Hello World with Ant tutorial from the Ant manual to learn about Ant. The last part of the tutorial involves adding JUnit tests to the project. I've got everything working as described in the tutorial and am now going on to make some minor changes. One of the changes I would like to make is to run the tests during a typical build but not have the *Test.class files end up in the final .jar file for the application. This is because the eventual project I will be working on will be

junit not using the newest file

夙愿已清 提交于 2019-12-18 07:53:05
问题 I use junit automatically installed by maven. When I run the maven test my tests work fine. But when I call the Eclipse JUnit test it doesn't use the current version of the test class. E.g. if I change a assertTrue() into a assertFalse() I get the same result. This is driving me crazy. Automatic build for the project is on. Why does JUnit use some old crap? Thanks for the help. A maven clean and a eclipse clean fixed the problem. Weird... 回答1: Most possibly Maven compiles to ./target/classes

Trying to run Android JUnit tests in Eclipse fails?

≡放荡痞女 提交于 2019-12-18 07:39:18
问题 I have seen all the examples on the web and it seems real simple. I have a bare-bones app that displays a string. I have a a Android JUnit test project that I created when the app was being created (eclipse asked if I wanted to create a test app). When I run the test app (Run As --- Android JUnit) I see the following in the console.... [2010-02-27 00:45:03 - SimpleCalculatorTest]Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 [2010-02-27 00:45:12 -

Mocking Objects Created Inside method Under test

坚强是说给别人听的谎言 提交于 2019-12-18 07:05:02
问题 I have a class which I would like to test.Whenever possible I would do dependency injections for that class which depends on object of other classes.But,I ran into a case where I would like to mock the object without restructuring the code and not appling DI. Here is the class under test: public class Dealer { public int show(CarListClass car){ Print print=new Print(); List<String> list=new LinkedList<String>(); list=car.getList(); System.out.println("Size of car list :"+list.size()); int

Loading Properties File In JUnit @BeforeClass

▼魔方 西西 提交于 2019-12-18 05:45:17
问题 I'm trying to load sample.properties from my classpath during my JUnit test execution and it can't find the file in the class path. If I write a Java Main class I'm able to load the file just fine. I'm using the below ant task to execute my JUnit. public class Testing { @BeforeClass public static void setUpBeforeClass() throws Exception { Properties props = new Properties(); InputStream fileIn = props_.getClass().getResourceAsStream("/sample.properties"); **props.load(fileIn);** } } JUnit:

RESTeasy client code for attaching a file

自古美人都是妖i 提交于 2019-12-18 05:14:14
问题 I need to attach a file to my service end-point . I tested the functionality via POSTMAN ( chrome browser plugin to test rest service ) , it is working fine. But I need to test the same with JUNIT . For that case I am using RESTeasy client . I was trying with this code : StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new FileReader("C:/Temp/tempfile.txt")); try { String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator

Using JMockit to mock autowired interface implementations

爷,独闯天下 提交于 2019-12-18 04:40:45
问题 We are writing JUnit tests for a class that uses Spring autowiring to inject a dependency which is some instance of an interface. Since the class under test never explicitly instantiates the dependency or has it passed in a constructor, it appears that JMockit doesn't feel obligated to instantiate it either. Up until now we have been using SpringRunner to have Spring load mock dependencies for us, which works. Two things we don't like about this are 1) the Spring framework has to be loaded