junit

How configure correctly @RunWith(Parameterized.class) + SpringClassRule + SpringMethodRule with a custom @Rule?

谁说胖子不能爱 提交于 2020-01-22 16:38:07
问题 I am working with Spring Framework 4.3.x and JUnit 4, I have the following structure @Transactional @WebAppConfiguration @RunWith(Parameterized.class) @ContextConfiguration(classes={RootApplicationContext.class, ServletApplicationContext.class}) @TestExecutionListeners(listeners={LoggingTestExecutionListener.class}, mergeMode=MergeMode.MERGE_WITH_DEFAULTS) public class CompleteTest { @ClassRule public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule(); @Rule public final

浅谈单元测试

陌路散爱 提交于 2020-01-22 13:03:50
单元测试或是最好的项目文档。 很早之前在学习使用Java做测试的时候,得到过一个神秘大佬的帮助,在一起聊过单元测试,基本结论就是:单元测试大概率没啥鸟用。 众所周知,自动化测试相比手动测试一个比较明显的特点就是见效慢,需要积累一定的时间所产生的的价值才能超过手动测试,这还是在比较理想的情况下。某些时候可能永远也超不过。而单元测试更甚,据大佬和吹牛逼的群聊中判断:好的单元测试代码大概是被测代码的2-3倍,这种工作量对于开发人员来讲是不可接受的。单元测试见效比自动化测试更慢,这一点也是大家的共识,甚至到不了见效的时候就黄了。 之前对单元测试进行过一些尝试,写过一点文章: Maven和Gradle中配置单元测试框架Spock Groovy单元测试框架spock基础功能Demo Groovy单元测试框架spock数据驱动Demo 人生苦短?试试Groovy进行单元测试 使用WireMock进行更好的集成测试 如何测试这个方法--功能篇 如何测试这个方法--性能篇 单元测试用例 JUnit 5和Selenium基础(一) JUnit 5和Selenium基础(二) JUnit 5和Selenium基础(三) 近几日一直在对之前的性能测试框架进行优化,在这个过程中,我之前利用Groovy单元测试框架spock写过的两个性能测试框架的单元用例起到了非常大的帮助

java程序测试

梦想与她 提交于 2020-01-22 12:50:48
java程序测试 软件测试 单元测试 总结 软件测试 定义:选择一组具有代表性的测试用例,然后检查算法的实际输出与预期输出是否一致。 1,单元测试:对单个程序单元进行测试 2,集成测试:将各程序单元组装起来进行测试 3,系统测试:将开发好的程序部署到实际运行环境中进行测试 单元测试 工具:JUnit(将每个java类都作为一个单独的测试单元) JUnit 使用: 1,程序员编写java类定义代码 2,测试员为java类设计测试用例,然后按照JUnit代码框架将测试用例编写成测试代码 3,测试员运行测试代码,若出现错误,提醒程序员修改,再测试,直至都通过 演示: JUnit导入 编写待测试类A.java: 新建测试用例类: 运行测试: 总结 因为java类中的各方法签名,在程序设计阶段确立的,方法体是在编码阶段具体实现,JUnit单元测试,是在输入一致的情况下,对比预期输出与程序输出是否相同,来检测算法真确性,以及健壮性,不涉及算法内部设计。java类测试程序可以做到“一次编写,长期使用”,除非类签名发生改变。 来源: CSDN 作者: MP-214 链接: https://blog.csdn.net/BennetMa/article/details/104067704

自动化测试入门

帅比萌擦擦* 提交于 2020-01-22 10:42:19
1 初识自动化测试 如果以前没有做过自动化测试,那么就不了解自动化测试,可能会觉得自动化测试比较神秘,但是,我们在日常的计算机操作中,可能会碰到一些自动化处理的过程,这些过程和自动化测试比较接近。 例如, Windows操作系统的控制面板中,有一项功能: 任务计划向导 。 DOS批处理文件,直到今天的Windows Vista还在使用它。它更接近自动化测试。 上述的自动化处理过程还不是测试,因为 测试的重要一点是须要验证 ,将实际执行的结果和用户期望的结果进行比较。没有这个比较,就不是自动化测试。 2 自动化测试和手工测试有什么不同 亲手做过自动化测试之后,我们对自动化测试就有了一个感性的认识,至少有下列几点感觉:   l 机器人从来就不会感觉累   l 自动化测试的速度,是手工测试无法比的   l 测试结果准确。例如搜索用时即使是0.33秒或0.24秒,系统都会发现问题,不会忽视任何差异。   l 一旦脚本完成,可以一劳永逸地运行很多遍,重复使用。 从这里就可以初步体会到自动化测试的优越性―― 高效率、准确可靠 和 复用性 。同时,自动化测试也有不利的一面,即在 创造性、发现新缺陷 等方面能力不足。 有资料显示,即使自动化测试实施良好,也只能发现软件系统中30%的问题,而70%的问题还要靠手工测试发现。所以 自动化测试更适合于负载测试、性能测试和回归测试 。 概括起来

Unit testing a class with autowired notation using Junit and EasyMock?

扶醉桌前 提交于 2020-01-22 05:14:31
问题 I am trying to write a Unit test for a class that has several of its fields marked @Autowired. Given the fact that Spring is automatically resolving the concrete implementations for these fields, I am having a hard time figuring out how to plug my Mock objects(created via EasyMock) as the dependencies during the test-run. Using @Autowired in the class means lack of setters in that class. Is there a way for me to plug my mock objects in without creating additional setters in class? Here's an

How to sequentially execute 2 Java classes via mvn command

自古美人都是妖i 提交于 2020-01-22 02:52:09
问题 I have 2 Java classes which have a symbiotic relationship. Class 1 produces some output files and Class 2 consumes the output of class 1 and validates it. Both of these classes take input from the commandline. This project is maven based. Given this symbiotic nature, I am unsure how to "connect them"? My thinking was, to write another Java class which takes in command line inputs and calls the 2 classes. However there is another uncertainty here, how could I run class 1 (in order to produce

Test expected an Exception, Exception was thrown (it shows in the output) but test failed anyway

[亡魂溺海] 提交于 2020-01-22 02:18:09
问题 Hi so there's a test for a constructor for a vehicle. The test initializes a vehicle with a driver without a driving license and it should throw an Exception. code constructor: public Voertuig(String Merk, Datum datumEersteIngebruikname, int Aankoopprijs, int Zitplaatsen, Mens bestuurder, Mens ... ingezetenen) { this.nummerplaat = div.getNummerplaat(); this.Zitplaatsen = Zitplaatsen; try { this.Merk = Merk; this.datumEersteIngebruikname = datumEersteIngebruikname; this.Aankoopprijs =

JUnit5 安装与使用

巧了我就是萌 提交于 2020-01-21 15:40:24
虽然 JUnit5 的测试版本早就出来了,但正式版直到几年 9 月份推出,目前最新版 5.0.1 。几乎所有的 Java 开发人员都会使用 JUnit 来做测试,但其实很多自动化测试人员也会使用 Junit 。目前, Android 单元测试默认使用 Junit4 ,相信不久的将来也会使用 JUnit5 。 但是介绍 JUnit5 安装与使用 资料并不算太多。本文普及一下 JUnit5 安装与基本使用。 什么是 Junit5 ? 先看来个公式: JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage 这看上去比 Junit4 复杂,实际上在导入包时也会复杂一些。 JUnit Platform 是在 JVM 上启动测试框架的基础。 JUnit Jupiter 是 JUnit5 扩展的新的编程模型和扩展模型,用来编写测试用例。 Jupiter 子项目为在平台上运行 Jupiter 的测试提供了一个 TestEngine (测试引擎)。 JUnit Vintage 提供了一个在平台上运行 JUnit 3 和 JUnit 4 的 TestEngine 。 环境: IDE : IntelliJ IDEA 版本工具: Maven 如果你从没使用过IntelliJ IDEA 和 Maven 的话,那么本文不适合你。 接下来在

Configuration for Gradle 4.7 to generate the HTML report for JUnit 5 tests

怎甘沉沦 提交于 2020-01-21 15:06:05
问题 I have an app based as follows: Spring Framework 5.0.4.RELEASE Gradle 4.7 - multimodule project configured through JUnit 5.1.1 The configuration about Gradle with JUnit is in the build.gradle file located in the root module: ... subprojects { apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.junit.platform.gradle.plugin' sourceCompatibility = '1.8' targetCompatibility = '1.8' repositories { jcenter() } ext { ... junitVersion = '5.1.1' ... } dependencies { ... //Testing ...

Missing branches when using assertTrue instead of assertNull

廉价感情. 提交于 2020-01-21 01:11:13
问题 In Java/Junit, I need to test for null with some object. There are a variety of ways I can test a condition but I have been using assertTrue for most of my tests. When I check for nulls in an assertTrue, EclEmma states that it is only testing one branch. When I resolve the statement into a variable manually (like setting the result to a boolean and passing it into assertTrue) the code coverage is deemed complete on the assert but not on the variable initializing line. Why is this happening?