junit

junit test method for getters & setters

…衆ロ難τιáo~ 提交于 2020-01-14 08:17:30
问题 I have many java beans in my project. I need to generate a JUnit Test class for them. The test methods generated using Eclipse 3.2 & junit 4.4 look like the following: public void testGetName() { // fail("Not yet implemented"); } @Test public void testSetName() { // fail("Not yet implemented"); } @Test public void testGetEmployeeid() { // fail("Not yet implemented"); } @Test public void testSetEmployeeid() { // fail("Not yet implemented"); } some of my beans have more than 100 fields... Is

junit and hamcrest declaration

我只是一个虾纸丫 提交于 2020-01-14 07:59:13
问题 I am using junit at 4.10 and declared hamcrest-core at 1.3 and hamcrest-library at 1.3. My question is are hamcrest-library and hamcrest-core embedded in junit 4.10. what about junit 4.11? <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> <version>1.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest<

Junit test fails when run on package, but success when run on file

放肆的年华 提交于 2020-01-14 04:16:13
问题 Big update: Has anyone run into this before? I'm using JUnit 4.5 and Mockito 1.7 in a Maven project. I have testCaseA.java in package testCaseFolder. if I open testCaseA.java, right click in the code, select "Run as" -"Junit test" it is okay. But if I right click package, select "Run as" -"Junit test", it will fail: org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Misplaced argument matcher detected! Somewhere before this line you probably misused Mockito argument matchers. For

Cannot run Unit Tests against REST layer

被刻印的时光 ゝ 提交于 2020-01-14 03:04:07
问题 I cannot unit test the web layer using jhipster (according to spring gs guides): @RunWith(SpringRunner.class) @WebMvcTest public class FlightControllerTest { @Autowired private MockMvc mockMvc; @MockBean private FlightService flightService; @Test public void testCreate() throws Exception { FlightDto expected = new FlightDto(); ReflectionTestUtils.setField(expected, "id", 1L); when(flightService.createFlight(any(FlightDto.class))).thenReturn(expected); FlightDto flightDto = new FlightDto();

Python测试框架之unittest和pytest 的区别

社会主义新天地 提交于 2020-01-13 20:12:08
一、Unittest Unittest是Python标准库中自带的单元测试框架,Unittest有时候也被称为PyUnit,就像JUnit是Java语言的标准单元测试框架一样,Unittest则是Python语言的标准单元测试框架。 Unittest支持自动化测试,测试用例的初始化、关闭和测试用例的聚合等功能,它有一个很重要的特性:它是通过类(class)的方式,将测试用例组织在一起。 示例: 执行结果: 注:unittest有一个关联模块unittest2,但unittest2仅适用于Python 2.4-2.6。这是由于从Python 2.7开始,unittest增加一些新的特性。为了在老的版本中支持这些特性,所以提供了unittest2这个库。但对于Python 2.7及之后的版本,unittest是唯一的。本次示例中使用的为python2.7。 二、Pytest Pytest是Python的另一个第三方单元测试库。它的目的是让单元测试变得更容易,并且也能扩展到支持应用层面复杂的功能测试。 pytest的特性有: 支持用简单的assert语句实现丰富的断言,无需复杂的self.assert*函数 自动识别测试模块和测试函数 模块化夹具用以管理各类测试资源 对 unittest 完全兼容,对 nose基本兼容 支持Python3和PyPy3 丰富的插件生态

How to run multiple test classes with junit from command line?

时光总嘲笑我的痴心妄想 提交于 2020-01-13 12:18:07
问题 I know that to run junit from command line you can do this: java org.junit.runner.JUnitCore TestClass1 [...other test classes...] However, I want to run many tests together and manually typing "TestClass1 TestClass2 TestClass3..." is just inefficient. Current I organize all test classes in a directory (which has sub-directories indicating the packages). Is there any way that I can run junit from command line and let it execute these test classes all at once? Thanks. 回答1: Basically there are

How to run multiple test classes with junit from command line?

徘徊边缘 提交于 2020-01-13 12:16:57
问题 I know that to run junit from command line you can do this: java org.junit.runner.JUnitCore TestClass1 [...other test classes...] However, I want to run many tests together and manually typing "TestClass1 TestClass2 TestClass3..." is just inefficient. Current I organize all test classes in a directory (which has sub-directories indicating the packages). Is there any way that I can run junit from command line and let it execute these test classes all at once? Thanks. 回答1: Basically there are

Trying to write junit test in Spring with JavaConfig

让人想犯罪 __ 提交于 2020-01-13 09:43:07
问题 I am trying to write a junit test for my example project but don't know how to access the ApplicationContext in the jUnit Test: Here is the main class of the project that works: public static void main(String[] args) { // in this setup, both the main(String[]) method and the JUnit method both specify that ApplicationContext context = new AnnotationConfigApplicationContext( HelloWorldConfiguration.class ); MessageService mService = context.getBean(MessageService.class); HelloWorld helloWorld =

Is there a version of JUnit assertThat which uses the Hamcrest 'describeMismatch' functionality?

蹲街弑〆低调 提交于 2020-01-13 09:37:05
问题 In every version of JUnit I have tried (up to 4.8.1), a failing assertThat will display an error message that looks like: expected: [describeTo] got: [String representation of object] In other words, it will display the toString() of the object instead of the mismatch description from the Matcher. If I use the assertThat from org.hamcrest.MatcherAssert.assertThat, then it will call 'describeMismatch' and display a more helpful error message. Am I using Junit incorrectly or is there currently

How to capture the exit status of a shell command in Java?

人盡茶涼 提交于 2020-01-13 08:39:11
问题 I'm creating a Junit test file for my CSVreader. I'm reading the contents of CSV files and writing the contents into another file. I want to compare them using diff utility and I want to use the exit status of diff to know whether the contents are same or not. Generally $? gives the exit status but I don't know how to capture it and use it in my code. Can anyone help me in this regard? This is how my code looks boolean hasSameContents = false; command="diff "+mp.get("directory")+"/"+fileName+