junit

JUNIT Null Pointer Exception

不羁岁月 提交于 2021-02-11 18:07:19
问题 it's my first time using JUNIT and I literally cannot get it to work. I've got a person class, in which has firstName and lastName, and a test class in which I need to test the methods. Everytime I attempt to test one though, if i've wrote a test for the particular method, it fails. Here is my code. Person Class public class Person { private String firstName; private String lastName; public Person (String a, String b) { firstName = a; lastName = b; } public String getfirstName() { return

JUNIT Null Pointer Exception

非 Y 不嫁゛ 提交于 2021-02-11 18:04:34
问题 it's my first time using JUNIT and I literally cannot get it to work. I've got a person class, in which has firstName and lastName, and a test class in which I need to test the methods. Everytime I attempt to test one though, if i've wrote a test for the particular method, it fails. Here is my code. Person Class public class Person { private String firstName; private String lastName; public Person (String a, String b) { firstName = a; lastName = b; } public String getfirstName() { return

Mocking an Aspect class invoked after an exception is thrown in Junit

為{幸葍}努か 提交于 2021-02-11 17:42:07
问题 I have an aspect class as below - public class TestAspect { @AfterThrowing(pointcut = "execution(* *(..)) ", throwing = "testException") public void afterThrowAdvice(TestException testException) throws Exception { } } Now anytime any class throws TestException, TestAspect's afterThrowAdvice method is getting called. From Unit tests as well without using any spring configuration xmls, running as a plain junit test. How do I mock to not do anything when that method is called? I tried in my unit

Import org.junit.Test throws error as “No Test found with Test Runner ”JUnit 5“” [duplicate]

夙愿已清 提交于 2021-02-11 14:29:36
问题 This question already has answers here : Eclipse keep saying “No tests found with test runner JUnit 5” (13 answers) Closed 1 year ago . If I import org.junit.Test then on running JUnit, it gives me an error as "No Test found with Test Runner JUnit 5". Instead if I import org.junit.jupiter.api.Test then I can run JUnit test. 回答1: This org.junit.Test is a JUnit 4 annotation. A Junit5 test runner will not discover a test annotated with org.junit.Test . A Junit5 test runner will discover a test

How to add data to testcase with JUnit and Maven Surefire Plugin

…衆ロ難τιáo~ 提交于 2021-02-11 14:27:30
问题 I have a running maven project with JUnit tests. The Maven Surefire Plugin drops xml files after the tests. These xml files include, besides properties and logprints, following information: <testcase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="methodNameForTest" classname="com.my.test.project.Testclass" time="20.931"> <error type="java.lang.NullPointerException">java.lang.NullPointerException</error> </testcase> Can someone explain me the usual way how data gets written from

How to tests and mock mapstruct converter?

痴心易碎 提交于 2021-02-11 14:21:50
问题 I use mapstruct frameword on my java gradle project and it works perfectly but i just want to test : mapstruct generated sources (converter) service class (call mapstrcut converter) I have try to use an other topic to do this but it not working for me. This is my mapstruct interface : @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface RisqueBOConvertisseur extends BOConvertisseur<RisqueARS, RisqueBO> { @Override RisqueBO convertirDaoVersBo(RisqueARS dao); @Override

How to tests and mock mapstruct converter?

落爺英雄遲暮 提交于 2021-02-11 14:21:10
问题 I use mapstruct frameword on my java gradle project and it works perfectly but i just want to test : mapstruct generated sources (converter) service class (call mapstrcut converter) I have try to use an other topic to do this but it not working for me. This is my mapstruct interface : @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface RisqueBOConvertisseur extends BOConvertisseur<RisqueARS, RisqueBO> { @Override RisqueBO convertirDaoVersBo(RisqueARS dao); @Override

Junit/Java create test method for void with exception

不羁的心 提交于 2021-02-11 13:32:55
问题 I want to create a test method for this void method: /** * @param speler speler die zijn wedstrijdronde heeft afgemaakt * @param score score van de speler * @throws GeenSpelerException als de persoon geen speler is */ @Override public void scoreToPar(Speler speler, int score) throws GeenSpelerException { if (speler.speeltWedstrijd(this.spelers,speler)) //boolean { throw new GeenSpelerException(); } speler.setScore(score); // set score into player I've made this test method for it: @Test void

Maven Surefire not running JUnit 5 tests

柔情痞子 提交于 2021-02-11 13:00:20
问题 I've been trying to run JUnit 5 tests with Maven Surefire. However, it doesn't seem like Surefire is running any tests at all, even though I do have some, and in the default directory, too. This is the console output I'm getting: https://prnt.sc/ugo1xt Here are the relevant parts of the pom.xml: <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.0-M1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins>

Maven Surefire not running JUnit 5 tests

风格不统一 提交于 2021-02-11 12:59:06
问题 I've been trying to run JUnit 5 tests with Maven Surefire. However, it doesn't seem like Surefire is running any tests at all, even though I do have some, and in the default directory, too. This is the console output I'm getting: https://prnt.sc/ugo1xt Here are the relevant parts of the pom.xml: <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.0-M1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins>