junit

@Autowired fails with JUnit & Spring

别说谁变了你拦得住时间么 提交于 2019-12-24 03:43:35
问题 Really need help. I used JUnit(4.6) plus Spring(3.0.5) for unit testing. When I tried to autowire a service object in my test class, I got a NoSuchBeanDefinitionException. The JUnit code: package com.aaa.service.impl; @ContextConfiguration(locations = { "classpath:/spring/applicationContext.xml", "classpath:/spring/applicationContext-aop.xml", "classpath:/spring/applicationContext-dao.xml", "classpath:/spring/applicationContext-service.xml" }) @RunWith(SpringJUnit4ClassRunner.class) public

JUnit test fails in Ant with `<junit>` task but passes with `<exec>`?

痴心易碎 提交于 2019-12-24 03:29:54
问题 I am automating my JUnit tests into my Ant build. However, my simple test only passes when run from the IDE and commandline but fails with Ant's <junit> task. When I run it from the commandline (I am technically using the Ant <exec> task) the result is: clean: compile_tests: [javac] Compiling 2 source files to C:\MY_TEMP junit_exec: [exec] JUnit version 4.10 [exec] . [exec] Time: 0.004 [exec] [exec] OK (1 test) [exec] BUILD SUCCESSFUL Total time: 1 second but when I use the <junit> task:

How do I print the stdout for unit test in Android?

混江龙づ霸主 提交于 2019-12-24 03:11:46
问题 I need a quick way to do a few tests and don't want to look at the Dalvik Debug Monitor. I just want to create a quick public static void main() and print some results to experiment with for debugging. I thought I could use the unit testing framework to get some results on the console stdout, but System.out.println() still goes to the log (as well as Log.d() ). So is there a way to print the the stdout when running a unit test? ant debug install test test: [echo] Running tests ... [exec]

Collect and run all junit tests in parallel with each test class in its own JVM (parallelization by class, not by method)

浪尽此生 提交于 2019-12-24 03:09:22
问题 Problem I've a bunch of junit tests (many with custom runners such as PowerMockRunner or JUnitParamsRunner) all under some root package tests (they are in various subpackages of tests at various depths). I'd like to collect all the tests under package tests and run each test class in a different JVM, in parallel. Ideally, the parallelization would be configurable, but a default of number_of_cores is totally fine as well. Note that I do not want to run each method in its own JVM, but each

Kotlin Mockito always return object passed as an argument

一世执手 提交于 2019-12-24 03:04:09
问题 I am trying to use Mockito on my mocked object in such a way that it should always return the very same object that was passed in as an argument. I tried it do to it like so: private val dal = mockk<UserDal> { Mockito.`when`(insert(any())).thenAnswer { doAnswer { i -> i.arguments[0] } } } However, this line always fails with: io.mockk.MockKException: no answer found for: UserDal(#1).insert(null) The insert(user: User) method doesn't take in null as an argument (obviously User is not a

JUnit @Theory : is there a way to throw meaningful exception?

五迷三道 提交于 2019-12-24 02:52:07
问题 I tried Junit @Theory test style recently : it's a really efficient way of testing. However, i not pleased with the exception that are thrown when a test fails. Example : import static org.junit.Assert.assertEquals; import org.junit.experimental.theories.DataPoint; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; @RunWith(Theories.class) public class TheoryAndExceptionTest { @DataPoint public static String

Gradle test fails with NullPointerException

徘徊边缘 提交于 2019-12-24 02:35:10
问题 I get this error when I run gradle test : Caused by: org.gradle.api.GradleException: Could not generate test report to '/home/tjwebb/workspace/MyProject/build/reports/tests'. Groovy 1.7.10 Gradle 1.0-m3 The weird thing is that my tests compile and run perfectly, they pass, and I get the usual output in build/reports/tests . Any ideas? 回答1: I guess this was a bug. I upgraded to gradle 1.0-m9 and it works. For some reason, m3 is the version still in the Ubuntu repositories. 来源: https:/

m2eclipse filtering test resources

我与影子孤独终老i 提交于 2019-12-24 02:22:41
问题 I am using m2eclipse and I want to right click and run tests from inside eclipse while the test resources get filtered from Maven. How can I do this? From eclipse when I right click on a test I do not get any m2eclipse options Julia. Similar to: Debugging maven junit tests with filtered resources? 回答1: Setup filtering in your pom.xml (and you'll get filtering under Eclipse with m2eclipse, m2eclipse runs process-resources after a change of any resource). Run your test as any other test ( right

Spring Security + Spring-Boot Testing Controller

谁说胖子不能爱 提交于 2019-12-24 02:13:07
问题 I'm trying to test the home controller @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } I'm using spring security using as username "user" and test as password by default but @PreAuthorize is not working @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @PreAuthorize("hasRole('ADMIN')") public class HomeControllerTest { @Autowired private TestRestTemplate restTemplate; @Test @WithMockUser(username = "user",

Could not find class Java JUnit

妖精的绣舞 提交于 2019-12-24 02:08:35
问题 I'm begginer in Java. Can you help me to find error? I run this using command line in Windows from the root folder of project. java -classpath lib/junit.jar;classes/ua/edu/sumdu/j2se/savchenko/pr2/Task.class org.junit.runner.JUnitCore ua.edu.sumdu.j2se.savchenko.pr2.tests.TaskTest My files location: classes/ua/edu/sumdu/j2se/savchenko/pr2/Task.class classes/ua/edu/sumdu/j2se/savchenko/pr2/tests/TaskTest.class lib/junit.jar 回答1: java -classpath lib/junit.jar;classes org.junit.runner.JUnitCore