junit4

Automatic mock instantiation in a Spring JUnit test

断了今生、忘了曾经 提交于 2019-11-30 01:48:30
问题 I have a Spring XML bean definition that I want to write integration tests for. The XML bean definition is part of a larger application context where several such files are included using <import> . Inside the definition, I reference several beans that are coming from other files. For my integration test I would like to instantiate the definition standalone and use Mockito mocks for all other beans. Until now, I am using something like this: FooIntegrationTest.java @RunWith

Running “pure” JUnit 4 tests using ant

孤街醉人 提交于 2019-11-30 01:41:18
We have migrated to both JUnit 4 and ant 1.7 The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant. According to the Ant junit task documentation : It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and no JUnit4TestAdapter. But the documentation doesn't elaborate on how it should be configured. Is there any special setting required for the junit task? Am I missing something? We have both Tests that extends TestCase (i.e. 3.8 style) and "pure" Junit 4 tests, could that be the problem? Homes2001 I am using pure JUnit4

How to share JUnit BeforeClass logic among multiple test classes

♀尐吖头ヾ 提交于 2019-11-30 00:04:14
Currently, all of my JUnit tests extend from a common base class that provides methods tagged with @BeforeClass and @AfterClass annotations - all these really do is setup a bunch of static resources/services for the tests to use. This seems a awkward to me for a few reasons: Part of the point of JUnit4 (from my understanding) is that we shouldn't need this classical test inheritance anymore. When I run these tests as part of a suite instead of individually (which we often do), the @BeforeClass and @AfterClass get invoked multiple times, slowing down the tests - we really should only be calling

junit testing with gradle for an android project

给你一囗甜甜゛ 提交于 2019-11-30 00:02:18
I am trying to get tests ( junit and robolectric ) working in an Android project but am totally stuck. My main problem is that all testing I found with gradle somehow pull in the java plugin and then I get this error: The 'java' plugin has been applied, but it is not compatible with the Android plugins. The only way out I see at the moment is to split into test and app project - but I would like to avoid that. Any examples/hints would be highly appreciated! In the official documentation there is no mention of unit-testing - only Instrumentation-Tests - but I want unit-tests to get results fast

How to execute JUnit and TestNG tests in same project using maven-surefire-plugin?

浪尽此生 提交于 2019-11-29 21:18:50
Right now I have both type of tests but when I say "mvn test" it only executes TestNG tests and not Junit. I want to execute both one after another. Any Idea ? There is an open issue for thi s, so there's no elegant way to do this. It would be far simpler for you to pick a framework and stick with it. Edit: My previous answer doesn't work because you can't specify dependencies in the execution. I've tried a few approaches, but the best I can manage is to create a profile for the TestNG dependency so you can toggle between TestNG and JUnit testing, there doesn't seem to be a means to run both

Why is JUnit 4 on Android not working?

旧街凉风 提交于 2019-11-29 21:03:00
as the documentation of Android says, "Note that the Android testing API supports JUnit 3 code style, but not JUnit 4." ( Testing Fundamentals ). It should be clear that JUnit 4 cannot be used out of the box with Android. But why is this the case? Is it because the tests are executed within the DVM (in that the Android Runtime only has support for JUnit 3)? On a JVM one on its own could choose the JUnit runtime that should be used. Isn't this possible within the DVM? Update 2015/10 It is now possible via the AndroidJUnitRunner, which is part of the Android Testing Support Library . In short,

Writing a single unit test for multiple implementations of an interface

只谈情不闲聊 提交于 2019-11-29 20:34:32
I have an interface List whose implementations include Singly Linked List, Doubly, Circular etc. The unit tests I wrote for Singly should do good for most of Doubly as well as Circular and any other new implementation of the interface. So instead of repeating the unit tests for every implementation, does JUnit offer something inbuilt which would let me have one JUnit test and run it against different implementations? Using JUnit parameterized tests I can supply different implementations like Singly, doubly, circular etc but for each implementation the same object is used to execute all the

Junit: splitting integration test and Unit tests

一笑奈何 提交于 2019-11-29 19:02:53
I've inherited a load of Junit test, but these tests (apart from most not working) are a mixture of actual unit test and integration tests (requiring external systems, db etc). So I'm trying to think of a way to actually separate them out, so that I can run the unit test nice and quickly and the integration tests after that. The options are.. Split them into separate directories. Move to Junit4 (from v3) and annotate the classes to separate them. Use a file naming convention to tell what a class is , i.e. AdapterATest and AdapterAIntergrationTest. 3 has the issue that Eclipse has the option to

Mockito + PowerMock LinkageError while mocking system class

岁酱吖の 提交于 2019-11-29 18:54:04
I've got such a code snippet: @RunWith(PowerMockRunner.class) @PrepareForTest({Thread.class}) public class AllMeasuresDataTest { @Before public void setUp() throws Exception { } @Test public void testGetMeasures() { AllMeasuresData measure = new AllMeasuresData(); assertEquals(measure.getMeasures(), null); HashMap<String, Measure> map = new HashMap<String, Measure>(); measure.setMeasures(map); assertEquals(measure.getMeasures(), map); measure.setMeasures(null); assertEquals(measure.getMeasures(), null); } @Test public void testAllMeasuresData() throws IOException { ClassLoader loader =

Why should I use Hamcrest-Matcher and assertThat() instead of traditional assertXXX()-Methods

风流意气都作罢 提交于 2019-11-29 18:46:24
When I look at the examples in the Assert class JavaDoc assertThat("Help! Integers don't work", 0, is(1)); // fails: // failure message: // Help! Integers don't work // expected: is <1> // got value: <0> assertThat("Zero is one", 0, is(not(1))) // passes I dont see a big advantage over, let's say, assertEquals( 0, 1 ) . It's nice maybe for the messages if the constructs get more complicated but do you see more advantages? Readability? Joachim Sauer There's no big advantage for those cases where an assertFoo exists that exactly matches your intent. In those cases they behave almost the same.