junit

Assert.assertEquals() fails for custom class objects [closed]

淺唱寂寞╮ 提交于 2019-12-20 07:58:37
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Even though I have two data objects of a custom class which are equal w.r.t all the variables, assertEquals() method is failing. What am I missing here? 回答1: For comparing two objects you need to override the equals() method of the Object class. When you create two objects of a class, say class A ,

软件工程 第二次作业

夙愿已清 提交于 2019-12-20 07:08:34
1. 选择开发工具   本次软件项目计划用Eclipse开发,本人电脑已经安装Eclipse,界面截图如下: 2. 练习自动单元测试技术 2.1 编写需要被测试的java类 建立Java Project 建立package,右键src,然后按下图所示操作: 输入包名 右键建立好的包,新建Java文件,注意以“.java”结束 写入要测试的类 2.2 导入Junit 2.3 规范JUnit 在src下新建source Floder取名为test 将之前Demo包移动到test文件夹下,并删除.java文件避免冲突 2.4 添加测试方法 在被测试的类Calculate上右键new一个JUnit Test Case 选择相应要测试的方法 显示出自动生成的测试方法 输入测试断言 2.5 运行测试类 2.6 运行结果分析 Runs:表示总共有几个测试方法,已经运行了几个; Errors:表示抛出异常的测试方法的个数; Failures:表示失败的测试方法的个数; 打钩:表示通过测试方法。 绿色的进度条表示测试成功,红色的进度条则表示测试失败。 来源: https://www.cnblogs.com/DLCodes/p/10696498.html

Running benchmark methods in a JUnit test class

帅比萌擦擦* 提交于 2019-12-20 07:00:42
问题 I have a test class MyTestClass with several typical test methods that do assertions or check for exceptions and are annotated with @Test . They run when I call the following directive in an Ant task: <test name="MyTestClass"/> However, in the same class I would like to situate several benchmark performance methods that are not included in the tests that must be passed. I would like to have an altogether separate Ant task that runs these benchmarking tests. Is there an annotated way to

Running benchmark methods in a JUnit test class

血红的双手。 提交于 2019-12-20 07:00:12
问题 I have a test class MyTestClass with several typical test methods that do assertions or check for exceptions and are annotated with @Test . They run when I call the following directive in an Ant task: <test name="MyTestClass"/> However, in the same class I would like to situate several benchmark performance methods that are not included in the tests that must be passed. I would like to have an altogether separate Ant task that runs these benchmarking tests. Is there an annotated way to

Coversion of Junit XML Report into HTML form [closed]

喜夏-厌秋 提交于 2019-12-20 06:28:54
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I am using soapui free version to generate the report of test cases,but it is only generating a junit report in XML form, now I want to convert that into an HTML form. 回答1: There are several ways to do that, but

Cannot test a class that return a customException

耗尽温柔 提交于 2019-12-20 06:27:18
问题 While experimenting JUnit, I am trying to test a simple private method as follows, this method receives a String and make sure it does not include the word 'Dummy' in it. I know, it is possible to put the test in the same package as the class and change access modifier of the method to package but I would like to use reflection to learn that. private void validateString(String myString) throws CustomException { if (myString.toLowerCase().matches(".*dummy.*")) throw new CustomException("String

Mockito - how to mock/verify a method call which accepts a new object?

瘦欲@ 提交于 2019-12-20 05:47:20
问题 I have a method (method1) that I'd like to test, which based on parameters provided creates an object and calls another method (method2). So I'm mocking method2, which accepts an object (sampleObj). public void method1(booleanParam) { if(booleanParam){ List<SampleObj> fooList = new ArrayList<SampleObj>; fooList.add(new SampleObj("another param")); anotherService.method2(fooList); } //some other smart logic here } And here's my test with same obfuscated names (sorry if I missed any typo):

JUnit testing for IO

依然范特西╮ 提交于 2019-12-20 05:47:05
问题 I am new here and new to junit testing. I have a class with two methods and I want to write unit tests for it. I am not sure how to start I read some basic tutorials but I am not able to start some how. Can anyone of you provide me some basic skeleton to start with. My class is public class CreateCSV { MyWriter csvOutput = null; public void createSortedSet ( final HashMap< String, Signal > map, final long totalSize, final long totalSizewithHeader, File file ) { ArrayList< Signal > messages =

JUnit for RestController with parameter PersistentEntityResourceAssembler

萝らか妹 提交于 2019-12-20 05:15:41
问题 could you please help me. I try to implement an JUnit-Test for a Restcontroller with parameter PersistentEntityResourceAssembler. Here is my RestController: import java.util.Map; import org.apache.camel.ProducerTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http

error compiling junit test with expect exception

ぐ巨炮叔叔 提交于 2019-12-20 05:13:23
问题 I am having difficulty using junit 4's expected annotation to look at exceptions. I can't compile the code because there's an unhandled exception. Here's a simple example that creates the situation: import static org.junit.Assert.*; import java.io.UnsupportedEncodingException; import org.junit.Test; public class Simple { @Test(expected=UnsupportedEncodingException.class) public void simpleTest(){ String a = ""; a.getBytes("UTF-123"); } } I get a compilation error saying "Unhandled exception