junit

JUnit-testing a Spring @Async void service method

柔情痞子 提交于 2019-12-18 11:44:55
问题 I have a Spring service: @Service @Transactional public class SomeService { @Async public void asyncMethod(Foo foo) { // processing takes significant time } } And I have an integration test for this SomeService : @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest @Transactional public class SomeServiceIntTest { @Inject private SomeService someService; @Test public void testAsyncMethod() { Foo testData =

Java 9 + maven + junit: does test code need module-info.java of its own and where to put it?

坚强是说给别人听的谎言 提交于 2019-12-18 11:17:30
问题 Let's say I have a Java project using Maven 3 and junit. There are src/main/java and src/test/java directories which contain main sources and test sources, respectively (everything is standard). Now I want to migrate the project to Java 9. src/main/java content represents Java 9 module; there is com/acme/project/module-info.java looking approximately like this: module com.acme.project { require module1; require module2; ... } What if test code needs module-info.java of its own? For example,

How to assert greater than using JUnit Assert?

℡╲_俬逩灬. 提交于 2019-12-18 11:16:36
问题 I have these values coming from a test previousTokenValues[1] = "1378994409108" currentTokenValues[1] = "1378994416509" and I try // current timestamp is greater assertTrue(Long.parseLong(previousTokenValues[1]) > Long.parseLong(currentTokenValues[1])); I get the java.lang.AssertionError and detailMessage on debugging is null . How can I assert greater than conditions in using JUnit 回答1: Just how you've done it. assertTrue(boolean) also has an overload assertTrue(String, boolean) where the

How to share JUnit BeforeClass logic among multiple test classes

风格不统一 提交于 2019-12-18 10:54:48
问题 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

junit testing with gradle for an android project

隐身守侯 提交于 2019-12-18 10:50:56
问题 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

How to get CTest results in Hudson / Jenkins

ε祈祈猫儿з 提交于 2019-12-18 10:35:31
问题 I'm using CTest (part of CMake) for my automated tests. How do I get CTest results in the Jenkins dashboard ? Or, phrased differently, how do I get CTest to output in JUnit-like XML ? 回答1: In Jenkins, after the CMake part (probably made through the CMake plugin), add the following batch script, or adapt for builds on Linux : del build_32\JUnitTestResults.xml pushd build_32\Tests "C:\Program Files\CMake 2.8\bin\ctest.exe" -T Test -C RelWithDebInfo --output-on-failure popd verify >nul C:

How can I test with junit that a warning was logged with log4j? [duplicate]

拜拜、爱过 提交于 2019-12-18 10:15:29
问题 This question already has answers here : How to do a JUnit assert on a message in a logger (24 answers) Closed 2 years ago . I'm testing a method that logs warnings when something went wrong and returns null. something like: private static final Logger log = Logger.getLogger(Clazz.class.getName()); .... if (file == null || !file.exists()) { // if File not found log.warn("File not found: "+file.toString()); } else if (!file.canWrite()) { // if file is read only log.warn("File is read-only: "

Testing Storm Bolts and Spouts

不想你离开。 提交于 2019-12-18 10:04:15
问题 This is a general question regarding Unit Testing Bolts and Spouts in a Storm Topology written in Java. What is the recommended practice and guideline for unit-testing (JUnit?) Bolts and Spouts ? For instance, I could write a JUnit test for a Bolt , but without fully understanding the framework (like the lifecycle of a Bolt ) and the Serialization implications, easily make the mistake of Constructor-based creation of non-serializable member variables. In JUnit, this test would pass, but in a

Unable to inject dependency in Junit test

允我心安 提交于 2019-12-18 09:49:14
问题 Having some trouble injecting a dependency in one of my JUnit test classes. I believe the TestApplication is not package scanning or is not being loaded. Code below: package com.mitto.repositories; import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org

Struts 2 Junit Test case execution failed (StrutsTestCase.getActionProxy:138 » NullPointer)

坚强是说给别人听的谎言 提交于 2019-12-18 09:37:28
问题 I created a sample struts 2 project & junit test case by referring the below link. http://self-learning-java-tutorial.blogspot.com.au/2015/04/struts2-junit-integration.html But, while executing the test case I am getting following error, Error in Eclipse JUNIT stacktrace Can Anyone advice me how to resolve this issue ? 回答1: The error in eclipse is resolved after adding the classes folder in the build path. But after I faced a new Issue during maven build test execution. 来源: https:/