junit

Run Junit-Tests from several projects conveniently fast in Eclipse

旧城冷巷雨未停 提交于 2019-12-18 18:49:06
问题 Is there a way to run JUnit-Tests from several projects conveniently fast in Eclipse? The JUnit-Runner lets you define a package or a folder where from all contained tests are executed. Is there a way to do this with tests from several projects inside Eclipse? Preferably it should be via the Junit-Runner. If there is some way to have it fast via an Ant-job (so not depend on a complete build with ant before), that would be also nice. 回答1: You can't do it through the UI. Looking at the

Misplaced argument matcher detected here. You cannot use argument matchers outside of verification or stubbing in Mockito

最后都变了- 提交于 2019-12-18 18:37:53
问题 Out of the following two test cases in BundleProcessorTest.java , i am getting below exception, although, my first test case passes successfully. org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Misplaced argument matcher detected here: -> at bundle.test.BundleProcessorTest.bundlePluginShouldNotBeNull(BundleProcessorTest.java:22) You cannot use argument matchers outside of verification or stubbing. Examples of correct usage of argument matchers: when(mock.get(anyInt()))

jar-with-dependencies and a managed dependency

让人想犯罪 __ 提交于 2019-12-18 18:32:56
问题 We have a parent project with about dozen child projects. Most of the child projects have tests, and so they depend on JUnit. I thought it would make sense to pull this out to the parent pom as a managed dependency: <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> In one of my child projects - still working on cleaning up this one - I need

jar-with-dependencies and a managed dependency

跟風遠走 提交于 2019-12-18 18:32:27
问题 We have a parent project with about dozen child projects. Most of the child projects have tests, and so they depend on JUnit. I thought it would make sense to pull this out to the parent pom as a managed dependency: <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> In one of my child projects - still working on cleaning up this one - I need

Handling unit tests with a condition on the current time

谁都会走 提交于 2019-12-18 14:39:10
问题 I'm taking a stab at setting up unit tests for some utility classes in a project I'm working on, and one of the classes (contains licensing info) has a method that does some determination based on the current time. i.e. the license contains an expiry date, and the license string validates that date, but the actual logic to see if the license is expired is based on the current time. public boolean isValid() { return isLicenseStringValid() && !isExpired(); } public boolean isExpired() { Date

Android Instrumentation Testing - UI Thread Issues

坚强是说给别人听的谎言 提交于 2019-12-18 14:18:23
问题 I am trying to write an Instrumentation Test for my Android app. I'm running into some weird threading issues and I can't seem to find a solution. My Original Test: @RunWith(AndroidJUnit4.class) public class WorkOrderDetailsTest { @Rule public ActivityTestRule<WorkOrderDetails> activityRule = new ActivityTestRule<>(WorkOrderDetails.class); @Test public void loadWorkOrder_displaysCorrectly() throws Exception { final WorkOrderDetails activity = activityRule.getActivity(); WorkOrder workOrder =

junit: impact of forkMode=“once” on test correctness

﹥>﹥吖頭↗ 提交于 2019-12-18 14:13:46
问题 I'd like to reduce the time which our build (using ant) takes for running the tests. Currently I am using the default forkMode, which forks a new vm on each test class ( perTest ). I am thinking about to switch to forkMode="once" but I am unsure if this will couple the tests somehow and maybe give me false positive and/or false negatives results after running my tests. Questions: Will each test case get a new ClassLoader so that all static references from previous runs are not accessible

How to solve “Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.” while running “ant test”?

烈酒焚心 提交于 2019-12-18 14:05:31
问题 I have a target named test and I want to do some tests. I put here the important parts in build.xml . It includes: <property name='lib.dir' value='lib' /> <path id='classpath'> <fileset dir="${lib.dir}" includes="**/*.jar" /> </path> And I have put the junit.jar and ant-junit.jar (is it a must?) in the lib directory. However, if I run ant test . The output error is: test: BUILD FAILED /home/xiaohan/EclipseWorkSpace/AntTest/build.xml:82: Problem: failed to create task or type junit Cause: the

单元测试C代码[关闭]

十年热恋 提交于 2019-12-18 13:45:22
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 今年夏天,我用直接C编写了一个嵌入式系统。这是我工作的公司接管的现有项目。 我已经习惯于使用JUnit在Java中编写单元测试,但是对于为现有代码(需要重构)编写单元测试的最佳方法以及添加到系统中的新代码感到茫然。 是否有任何项目使单元测试普通C代码与使用JUnit进行单元测试Java代码一样简单? 任何专门针对嵌入式开发(交叉编译到arm-linux平台)的见解都将非常感激。 #1楼 我个人喜欢 Google Test框架 。 测试C代码的真正困难在于打破了对外部模块的依赖性,因此您可以将代码单独隔离。 当您尝试围绕遗留代码进行测试时,这可能会特别成问题。 在这种情况下,我经常发现自己使用链接器在测试中使用存根函数。 这是人们在谈论“ 接缝 ”时所指的。 在C中,您唯一的选择就是使用预处理器或链接器来模拟您的依赖项。 我的一个C项目中的典型测试套件可能如下所示: #include "myimplementationfile.c" #include <gtest/gtest.h> // Mock out external dependency on mylogger.o void Logger_log(...){} TEST(FactorialTest, Zero) { EXPECT_EQ(1,

Running JUnit Test in parallel on Suite Level?

久未见 提交于 2019-12-18 13:14:45
问题 I have a bunch of tests that are organized in JUnit test suites. These tests are greatly utilizing selenium to test a web application. So, naturaly for selenium, the runtime of these tests is quite long. Since the test classes in the suites can not run parallel due some overlaps in the test database, i would like to run the suites parallel. The JUnit ParallelComputer can only execute tests on class or method level in parallel, are there any standard ways for JUnit to do that with suites? If i