junit

Does JUnit execute test cases sequentially?

这一生的挚爱 提交于 2019-12-29 04:27:12
问题 In this post, I asked a small question as part of a bigger problem. Since I didn't get responses yet, I put my question here: Is it reasonable to suppose that JUnit executes test cases sequentially: a test case ends befores the next one starts. Does it differ between JUnit versions (my priority is on JUnit4)? And if not, is there a simple way to force JUnit to execute tests sequentially? Thank you 回答1: Yes, by default I believe it runs tests sequentially. JUnit 4.6 introduced an experimental

Easy way to get a test file into JUnit

心已入冬 提交于 2019-12-29 03:12:31
问题 Can somebody suggest an easy way to get a reference to a file as a String/InputStream/File/etc type object in a junit test class? Obviously I could paste the file (xml in this case) in as a giant String or read it in as a file but is there a shortcut specific to Junit like this? public class MyTestClass{ @Resource(path="something.xml") File myTestFile; @Test public void toSomeTest(){ ... } } 回答1: You can try @Rule annotation. Here is the example from the docs: public static class

spring 3 autowiring and junit testing

随声附和 提交于 2019-12-29 02:39:13
问题 My code: @Component public class A { @Autowired private B b; public void method() {} } public interface X {...} @Component public class B implements X { ... } I want to test in isolation class A. Do I have to mock class B? If yes, how? Because it is autowired and there is no setter where i could send the mocked object. 回答1: I want to test in isolation class A. You should absolutely mock B, rather than instantiate and inject an instance of B. The point is to test A whether or not B works, so

一键自动生成 java junit 测试代码神器 gen-test-plugin 入门介绍

最后都变了- 提交于 2019-12-28 22:32:12
gen-test-plugin 我们日常编写代码的过程中,经常需要为代码编写测试案例。 随着对代码质量的要求越来越高,很多公司开始通过代码的测试覆盖率作为 QA 的一个评定指标。 本框架可以一键生成所有代码对应的 junit 测试案例,为你的人生节约宝贵的时间。 特性 支持生成 junit4/junit5 支持 jdk7 支持自定义生成模板 更新记录 更新记录 gen-test 用于生成 Junit4/Junit5 单元测试。 引入 <plugin> <groupId>com.github.houbb</groupId> <artifactId>gen-test-plugin</artifactId> <version>0.0.1</version> </plugin> 属性说明 属性 说明 默认值 类型 备注 isOverwriteWhenExists 如果 test 文件已存在,是否覆盖 false 字符串 默认不进行覆盖 encoding 项目编码 utf-8 字符串 includes 包含文件正则 **\/*.java 字符串 默认为所有 java 文件 excludes 排除文件正则 字符串 默认不进行排除 junitVersion junit 版本 4 字符串 默认为 junit4 运行 命令行直接执行 mvn com.github.houbb:gen-test

Passing JUnit data between tests

蓝咒 提交于 2019-12-28 16:30:39
问题 I just discovered when creating some CRUD tests that you can't set data in one test and have it read in another test (data is set back to its initialization between each test). All I'm trying to do is (C)reate an object with one test, and (R)ead it with the next. Does JUnit have a way to do this, or is it ideologically coded such that tests are not allowed to depend on each other? 回答1: Well, for unit tests your aim should be to test the smallest isolated piece of code, usually method by

AndroidManifest in androidTest directory being ignored

纵饮孤独 提交于 2019-12-28 12:01:11
问题 I'm trying to test using the following directory structure (which was setup by Android Studio): I can run some tests just fine, and even the AllTests.java runs fine without the AndroidManifest.xml file even being there. The thing is, for one of my new tests, I need the android.permission.INTERNET permission. So, I added the following to the AndroidManifest.xml file located within the androidTest directory: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com

AndroidManifest in androidTest directory being ignored

*爱你&永不变心* 提交于 2019-12-28 12:01:11
问题 I'm trying to test using the following directory structure (which was setup by Android Studio): I can run some tests just fine, and even the AllTests.java runs fine without the AndroidManifest.xml file even being there. The thing is, for one of my new tests, I need the android.permission.INTERNET permission. So, I added the following to the AndroidManifest.xml file located within the androidTest directory: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com

Selenium and Edge Dev (Chromium based)

﹥>﹥吖頭↗ 提交于 2019-12-28 06:51:32
问题 I'm trying to run a Selenium test with Java and Edge Dev (based on Chromium). I have downloaded the driver binary ( msedgedriver.exe , 64-bits in my case) from here. The version of my Edge Dev installed on Windows 10 is 76.0.152.0 (Official build dev 64-bit): Then, I have the following JUnit 4 test: import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import

Can Selenium take a screenshot on test failure with JUnit?

江枫思渺然 提交于 2019-12-28 06:18:20
问题 When my test case fails, especially on our build server, I want to take a picture / screenshot of the screen to help me debug what happened later on. I know how to take a screenshot, but I was hoping for a way in JUnit to call my takeScreenshot() method if a test fails, before the browser is closed. No, I don't want to go edit our bazillions of tests to add a try/catch. I could maybe, just possibly be talked into an annotation, I suppose. All of my tests have a common parent class, but I can

Mockito - Invalid use of argument matchers

五迷三道 提交于 2019-12-28 05:56:15
问题 I have Junit test that is testing jms message sending. I am using Spring jmsTemplate to to do this. Here I as in the following code I want to check whether the JMS template has called send message regardless what is it in the values of actuall parameters that are passed. my publisher method the uses the jmsTemplate to send method looks like following inside.. jmsTemplate.send(jmsQueueProperties.getProperty(key), new MessageCreator() { public Message createMessage(Session session) throws