junit

Intellij IDEA code coverage doesn't work

你离开我真会死。 提交于 2021-02-18 12:56:05
问题 When I'm trying to run my JUnit tests with coverage I receive the following error FATAL ERROR in native method: processing of -javaagent failed java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.instrument

Syntax error: insert “enum Identifier”, insert “EnumBody”, inset “}”

▼魔方 西西 提交于 2021-02-18 11:57:05
问题 I coded an enum type which brings up the following Syntax errors when I run my created JUnit test for it: java.lang.Error: Unresolved compilation problems: Syntax error, insert "enum Identifier" to complete EnumHeaderName Syntax error, insert "EnumBody" to complete EnumDeclaration Syntax error, insert "}" to complete ClassBody My enum type has static functions which for a particular String, returns an enum constant. Here is some of my code of the enum type: public enum MusicType { ACCIDENTAL,

Test lambda expressions called by dependencies

夙愿已清 提交于 2021-02-18 11:47:31
问题 I am trying to test some code inside lambda expression which is a call back from another class. class EmailSender { private EmailBuilder emailBuilder; public void send() { String testEmail = emailBuilder.buildEmail("Test Email", bodyContentAppender()); //send testEmail } private Consumer<Email> bodyContentAppender() { //how to test this through JUnit? return email -> email.appendBody("Body Content"); } } interface EmailBuilder { String buildEmail(String templateName, Consumer<Email>

Run JUnit tests from a dependency jar in Eclipse

限于喜欢 提交于 2021-02-18 10:38:49
问题 I have some JUnit tests that contained in a .jar that is intended to be used as a library. The library contains some tests that should be run whenever the library is used in another project. However when I create a new project using the library and run JUnit on it in Eclipse then the tests in the dependency .jar don't run / don't get detected by the JUnit test runner. I get the message: No tests found with test runner 'JUnit 4'. Is there a way I can configure the dependency .jar so that the

NUnit: How to pass TestCaseData from a non-static method?

≯℡__Kan透↙ 提交于 2021-02-18 05:02:48
问题 my test fails because of : Message: The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method. This is my Code: const double MAX_DELTA = 0.01; Qv_ges qv_ges_NE; double Sum_Qv_ges_R_FL; Qv_ges Qv_ges_Quer; [SetUp] public void init() { qv_ges_NE = Din1946.Calc_Qv_ges_NE(205.7d); Sum_Qv_ges_R_FL = 15d + 15d + 15d + 15d + 15d + 10d + 10d + 10d + 10d + 10d + 10d + 10d; Qv_ges_Quer = Din1946.Calc_Qv_ges_Quer(qv_ges_NE, Sum_Qv_ges_R_FL); } public

How to mock persisting and Entity with Mockito and jUnit

半城伤御伤魂 提交于 2021-02-18 01:22:01
问题 I'm trying to find a way to test my entity using Mockito; This is the simple test method: @Mock private EntityManager em; @Test public void persistArticleWithValidArticleSetsArticleId() { Article article = new Article(); em.persist(article); assertThat(article.getId(), is(not(0L))); } How do I best mock the behaviour that the EntityManager changes the Id from 0L to i.e. 1L? Possibly with the least obstructions in readability. Edit: Some extra information; Outside test-scope the EntityManager

How to mock persisting and Entity with Mockito and jUnit

痴心易碎 提交于 2021-02-18 01:17:03
问题 I'm trying to find a way to test my entity using Mockito; This is the simple test method: @Mock private EntityManager em; @Test public void persistArticleWithValidArticleSetsArticleId() { Article article = new Article(); em.persist(article); assertThat(article.getId(), is(not(0L))); } How do I best mock the behaviour that the EntityManager changes the Id from 0L to i.e. 1L? Possibly with the least obstructions in readability. Edit: Some extra information; Outside test-scope the EntityManager

Junit5常用注解

有些话、适合烂在心里 提交于 2021-02-18 00:35:03
0. IDEA中Maven项目测试类的新建方法 a. 如图在src目录下新建文件夹test b. 鼠标右键test,将该文件设置成test source c. 右键需要新建的测试类,如下图操作,选中Test,即可新建测试类。 1. @BeforeEach与@BeforeAll @BeforeEach 在运行类测试时,每个方法执行前都会执行一次此注解修饰的方法; @BeforeAll 在以运行类测试时,所有方法执行前仅执行一次此注解修饰的方法; 2.@Order和@TestMethodOrder 此注解主要用于使测试的方法顺序执行,需要与@TestMethodOrder结合使用,示例如下: import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; @TestMethodOrder(OrderAnnotation.class) class OrderedTestsDemo { @Test @Order(1) void nullValues() { // perform assertions

JUnit5 快速指南

纵然是瞬间 提交于 2021-02-17 23:50:31
JUnit5 快速指南 version: junit5 <!-- TOC depthFrom:2 depthTo:3 --> 1. 安装 2. JUnit 注解 3. 编写单元测试 3.1. 基本的单元测试类和方法 3.2. 定制测试类和方法的显示名称 3.3. 断言(Assertions) 3.4. 假想(Assumptions) 3.5. 禁用 3.6. 测试条件 3.7. 嵌套测试 3.8. 重复测试 3.9. 参数化测试 4. 引用和引申 <!-- /TOC --> 1. 安装 在 pom 中添加依赖 <properties> <junit.jupiter.version>5.3.2</junit.jupiter.version> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.jupiter.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter

No tasks available when executing JUnit runner class

廉价感情. 提交于 2021-02-17 21:10:16
问题 I am trying to run Cucumber feature files in IntelliJ. Cucumber Options is pointing to the right folder, but I get the "No tasks available" notification when trying to execute the JUnit runner class. What am I doing wrong? Here is my build.gradle : plugins { id 'java' } sourceCompatibility = 1.8 apply plugin: 'java' repositories { mavenCentral() } compileJava.options.encoding = "UTF-8" dependencies { compile 'org.codehaus.groovy:groovy-all:2.3.11' testCompile group: 'junit', name: 'junit',