junit

junit test should use main/resources

前提是你 提交于 2019-12-18 04:31:50
问题 I have a problem with maven and JUnit testing. I have some files in src/main/resources and when running junit tests I want to these files. Only one test specific file with slightly different settings should overrule a corresponding file. So my idea was to give this test-file the same name like the main-file and put it file under src/test/resources at the same (corresponding) place like the main-file. But now I have the problem, that I cant use all the other files from src/main/resources. I

RunWith and ContextConfiguration weird behaviour

流过昼夜 提交于 2019-12-18 04:12:09
问题 I have this very simple class : @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath*:/application-context-this-does-not-exist.xml"}) public class HTMLSourceExtractorImplTest { @Autowired ApplicationContext context; @Test public void test(){ String [] beans = context.getBeanDefinitionNames(); for(String bean : beans){ System.out.println(bean); } System.out.println("Testing"); } } This context file that is specified in classpath DOES NOT EXIST. I can put

How to create an HTML report for JUnit 5 tests?

你离开我真会死。 提交于 2019-12-18 04:09:41
问题 Is there already a possibility to generate an HTML report when JUnit tests were started via Gradle? Any hint or comment is appreciated. 回答1: UPDATE Gradle 4.6 provides built-in support for the JUnit Platform which allows you to run JUnit Jupiter tests using the standard Gradle test task which generates HTML reports out of the box. Answer for Gradle versions prior to 4.6 The JUnit Platform Gradle Plugin generates JUnit 4 style XML test reports. These XML files are output to build/test-results

!!! JUnit version 3.8 or later expected [duplicate]

别等时光非礼了梦想. 提交于 2019-12-18 03:53:02
问题 This question already has answers here : IntelliJ IDEA with Junit 4.7 “!!! JUnit version 3.8 or later expected:” (21 answers) Closed 2 years ago . My Android studio project has an app module which is android framework dependent, I have created a new module called domain and it contains only pure java classes and a few test classes. In this module's build.gradle file, I have added junit and mockito libraries for testing purpose as follows: apply plugin: 'java' sourceCompatibility = 1.7

Compare Date objects with different levels of precision

旧街凉风 提交于 2019-12-18 03:51:46
问题 I have a JUnit test that fails because the milliseconds are different. In this case I don't care about the milliseconds. How can I change the precision of the assert to ignore milliseconds (or any precision I would like it set to)? Example of a failing assert that I would like to pass: Date dateOne = new Date(); dateOne.setTime(61202516585000L); Date dateTwo = new Date(); dateTwo.setTime(61202516585123L); assertEquals(dateOne, dateTwo); 回答1: Use a DateFormat object with a format that shows

!!! JUnit version 3.8 or later expected [duplicate]

試著忘記壹切 提交于 2019-12-18 03:50:59
问题 This question already has answers here : IntelliJ IDEA with Junit 4.7 “!!! JUnit version 3.8 or later expected:” (21 answers) Closed 2 years ago . My Android studio project has an app module which is android framework dependent, I have created a new module called domain and it contains only pure java classes and a few test classes. In this module's build.gradle file, I have added junit and mockito libraries for testing purpose as follows: apply plugin: 'java' sourceCompatibility = 1.7

How to start and stop an Tomcat container with Java?

≯℡__Kan透↙ 提交于 2019-12-18 03:25:16
问题 I have a Maven project that starts a tomcat container for pre-integration-tests (jUnit Tests). Most of my tests require that the web-application under tests is restarted. So I'd like to restart the Tomcat container before each jUnit test is executed. As for now I use the cargo-maven2-plugin to configure the tomcat container. So, is it possible to start and stop the container with a java statement? 回答1: So, is it possible to start and stop the container with a java statement? Your use case

How can I use the Parameterized JUnit test runner with a field that's injected using Spring?

末鹿安然 提交于 2019-12-18 03:05:29
问题 I'm using Spring to inject the path to a directory into my unit tests. Inside this directory are a number of files that should be used to generate test data for parameterized test cases using the Parameterized test runner. Unfortunately, the test runner requires that the method that provides the parameters be static. This doesn't work for my situation because the directory can only be injected into a non-static field. Any ideas how I can get around this? 回答1: I assume you are using JUnit 4.X

Running JUnit tests with Maven under Eclipse

强颜欢笑 提交于 2019-12-18 02:41:49
问题 I just installed the plugin m2e for the first time on Eclipse. I wrote a simple JUnit (version 4) test. I can run it from Eclipse, but not from the pom.xml (alt-click, Run as, Maven Test). I suppose I need to tell Maven to search for that class, but I just don't know how. Also, I couldn't find JUnit 4 in the groupId "junit": only the version 3.8.1 is available. Do I really need to write tests for version 3.x and not version 4+? How to fix this? Think of me as a newbie with Maven: that's

Mockito gives UnfinishedVerificationException when it seems OK

情到浓时终转凉″ 提交于 2019-12-18 01:25:44
问题 Mockito appears to be throwing an UnfinishedVerificationException when I think I've done everything correctly. Here's my partial test case: HttpServletRequest req = mock(HttpServletRequest.class); when(req.getHeader("Authorization")).thenReturn("foo"); HttpServletResponse res = mock(HttpServletResponse.class); classUnderTest.doMethod(req, res); // Use the mock verify(res, never()); verify(req).setAttribute(anyString(), anyObject()); And here's the partial class and method: class