junit

Is there any handy code coverage tool to be used with JUnit?

夙愿已清 提交于 2020-01-01 07:33:13
问题 Is there handy code coverage tool to be used with JUnit? 回答1: I would imagine most code coverage tools can be used pretty easily with JUnit. Previously I've used EMMA, which is good. If you're an Eclipse user, there's an Eclipse plugin called EclEmma to integrate things. 回答2: Here are my preferences in that order: EclEmma Clover And here is a bunch of open source tools and with comparison. Hope that helps. 回答3: There are many and google is your friend. NoUnit Coverlipse (I would recommend

Spring data jpa repository In-memory test case

北战南征 提交于 2020-01-01 07:22:24
问题 In My project I wrote a repository class for that i need to write in-memory test class. My Repository code is as follows. package org.jaap.reference.repository; import java.util.List; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QueryDslPredicateExecutor; import org.springframework.stereotype.Repository; import org.jaap.entity

Spring MVC unit tests - can I pass URL (with params) to controller?

让人想犯罪 __ 提交于 2020-01-01 07:11:17
问题 I am going to unit test a Spring MVC controller (or whole site if possible). I want to pass a URL (as a string), e.g. "/metrics/filter?a1=1&a2=2&a3=abcdefg&wrongParam=WRONG" and check what controller will return. Is there an easy way to do it? Example: @RequestMapping(value = {"/filter"}, method = RequestMethod.GET) @ResponseBody public List<MetricType> getMetricTypes( @RequestParam(value = "subject", required = false) Long subjectId ,@RequestParam(value = "area", required = false) Long

How to configure logging in Play Framework 2.0 for Junit tests

二次信任 提交于 2020-01-01 07:08:08
问题 While using Eclipse > Run as Junit Test or the play command line, only the errors are logged to the console. How to show warning, info, and debug messages generated during Junit tests ? app/controllers/Application.java package controllers; import play.*; import play.mvc.*; public class Application extends Controller { public static Result index() { Logger.trace("**** Logger.isTraceEnabled = " + Logger.isTraceEnabled()+ " *****"); Logger.debug("**** Logger.isDebugEnabled = " + Logger

Create junit automatically [closed]

﹥>﹥吖頭↗ 提交于 2020-01-01 05:17:04
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Is there any way that i need not write junit test cases and it gets generated automatically. Actually i have an application which is fully tested but has no junit written for it. So i am sure that it is complete and has not much error. But my client wants a code coverage report for the same. Is there any tool

Junit ant task - JUnitTask was not found

徘徊边缘 提交于 2020-01-01 05:02:29
问题 I'm trying to run Junit test from my ant build.xml file. I read here that you can use a junit.jar file instead of using the .jar that is located in the ant.home/lib directory. This is what I want to do since our Jenkins autobuild set-up has no junit.jar file in his ant lib directory. Even with the simpliest project, I'm always getting this error that the JUnitTask was not found. If you look at my build.xml file, it is clearly included and used in the junit task. build.xml : <project default=

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

大憨熊 提交于 2020-01-01 04:46:17
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

Unit test Android, getString from resource

China☆狼群 提交于 2020-01-01 04:19:47
问题 I am trying to do an unit test for an android app and I need to get a string from res.string resources. The class that I want to test is a POJO class. I am doing the app in two languages, due to this, I need to get a string from resource. The problem is that I cannot get the context or the activity, is possible? I know that with Instrumentation test I can do it, but I need to test some functions (white box test) before to do the instrumentation test (black box test). This is the function that

Unit test Android, getString from resource

本秂侑毒 提交于 2020-01-01 04:19:25
问题 I am trying to do an unit test for an android app and I need to get a string from res.string resources. The class that I want to test is a POJO class. I am doing the app in two languages, due to this, I need to get a string from resource. The problem is that I cannot get the context or the activity, is possible? I know that with Instrumentation test I can do it, but I need to test some functions (white box test) before to do the instrumentation test (black box test). This is the function that

JUnit @BeforeClass non-static work around for Spring Boot application

落花浮王杯 提交于 2020-01-01 04:01:22
问题 JUnit's @BeforeClass annotation must be declared static if you want it to run once before all the @Test methods. However, this cannot be used with dependency injection. I want to clean up a database that I @Autowire with Spring Boot, once before I run my JUnit tests. I cannot @Autowire static fields so I need to think of a work around. Any ideas? 回答1: Just use @Before (instead of @BeforeClass ) (or BeforeTransaction (depending on how you initialize the database)). This annotation must been