cobertura

如何测试私有函数或具有私有方法,字段或内部类的类?

半腔热情 提交于 2019-12-03 22:34:06
如何对具有内部私有方法,字段或嵌套类的类进行单元测试(使用xUnit)? 还是通过 内部链接 (在C / C ++中为 static )或在私有( 匿名 )名称空间中使其私有化的函数? 仅仅为了能够运行测试而更改方法或函数的访问修饰符似乎很糟糕。 #1楼 过去,我曾使用 反射 来为Java执行此操作,我认为这是一个很大的错误。 严格来说,你 不 应该编写单元测试直接测试私有方法。 您 应该 测试的是该类与其他对象之间的公共合同; 您永远不要直接测试对象的内部。 如果另一个开发人员想要对该类进行小的内部更改,而不影响该类的公共合同,则他/她必须修改您基于反射的测试以确保它可以工作。 如果您在整个项目中重复执行此操作,则单元测试将不再是对代码运行状况的有用衡量,并开始成为开发的障碍和开发团队的烦恼。 我建议做的是使用诸如Cobertura之类的代码覆盖工具,以确保您编写的单元测试以私有方法提供对代码的适当覆盖。 这样,您可以间接测试私有方法的功能,并保持更高的敏捷性。 #2楼 今天,我推出了一个Java库来帮助测试私有方法和字段。 它的设计考虑了Android,但实际上可以用于任何Java项目。 如果您使用私有方法或字段或构造函数获取一些代码,则可以使用 BoundBox 。 它确实满足您的需求。 以下是一个测试示例,该示例访问一个Android活动的两个私有字段进行测试:

Cannot install Cobertura plugin for Eclipse

非 Y 不嫁゛ 提交于 2019-12-03 22:13:33
I am getting following error message when I tried to install cobertura plugin in eclipse kepler (java/j2ee version) through eclipse market place. Cannot complete the install because one or more required items could not be found. Software being installed: eCobertura 0.9.8.201007202152 (ecobertura.feature.group 0.9.8.201007202152) Missing requirement: eCobertura 0.9.8.201007202152 (ecobertura.feature.group 0.9.8.201007202152) requires 'org.junit4 0.0.0' but it could not be found I was able to get eCobertura to install by copying over the junit plugin subdirectories from a previous version of

Code coverage for Android (calabash-android BDD)

巧了我就是萌 提交于 2019-12-03 16:45:38
I'm testing my android application using calabash-android which provides it's own "test project", with a script that renames it's package to reflect the app under test, and then uses an InstrumentationTestRunner subclass: adb shell am instrument -w -e class sh.calaba.instrumentationbackend.InstrumentationBackend #{ENV['TEST_PACKAGE_NAME']}/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner I'll accept any answer that allows me to generate a code coverage report similar to Emma or Cobertura for an Android app, with data collected while being tested in calabash-android. In

double unit test reporting with hudson and maven

时光总嘲笑我的痴心妄想 提交于 2019-12-03 13:11:58
I have a maven2 project in hudson and when the cobertura reporting plugin runs, it causes the unit tests to show that they have run twice. I don't mind them running multiple times, but the trend graph shows twice as many tests as we actually are running. Is there a way to make sure the graph only shows them once? thanks, Jeff This is a known bug. Just wait for it to be fixed. The workaround I use (works in Hudson 1.391) is to configure cobertura in separate Maven profile and run it in a Hudson job as a post-build step. Mode detailed instructions: Add cobertura to your project pom in a special

Unit tests passing through Maven, but failing through Cobertura: “Expecting a stackmap frame at branch target 65”

∥☆過路亽.° 提交于 2019-12-03 09:59:14
I recently added the Cobertura plugin to my Java/Spring-MVC project. The strange thing is that all my unit tests were passing, and they still pass when Maven does its initial test run, but then when Cobertura tries to run the tests, they all fail with the same error message: Expecting a stackmap frame at branch target 65 in method xxx.xxxx.xxxx.xxxx;)V at offset 40 I have no idea why this is happening and don't even know how to go about fixing it. I've searched the internet but haven't found any similar problems. I use JUnit and spring-test-mvc for testing. Has anyone seen this before? Of

How do I get Emma or Cobertura, with Maven, to report coverage on source code in other modules?

廉价感情. 提交于 2019-12-03 05:13:38
问题 I have a multi-module Maven setup with Java code. My unit tests, in one of the modules, exercise code in multiple modules. Naturally, the modules have inter-dependencies, and code in all relevant modules is compiled as needed in advance of test execution. So: How can I get a report on the coverage of the entire codebase? Note: I am not asking how to combine the results of coverage for tests in multiple modules. I am asking how to get coverage for tests in a single module using instrumented

Maven Cobertura plugin not generating coverage.xml

老子叫甜甜 提交于 2019-12-03 04:07:00
问题 I am trying to generate a coverage.xml so that I can reference it in Cobertura plugin of Hudson, but the file is not being created. I've added the following to my POM <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> </plugin> </plugins> </reporting> After running mvn cobertura:cobertura, the HTML site is

How do I get Emma or Cobertura, with Maven, to report coverage on source code in other modules?

老子叫甜甜 提交于 2019-12-02 18:28:56
I have a multi-module Maven setup with Java code. My unit tests, in one of the modules, exercise code in multiple modules. Naturally, the modules have inter-dependencies, and code in all relevant modules is compiled as needed in advance of test execution. So: How can I get a report on the coverage of the entire codebase? Note: I am not asking how to combine the results of coverage for tests in multiple modules. I am asking how to get coverage for tests in a single module using instrumented code from multiple modules. Anyone interested in the former might refer to these other questions , and

Maven Cobertura plugin not generating coverage.xml

▼魔方 西西 提交于 2019-12-02 17:26:40
I am trying to generate a coverage.xml so that I can reference it in Cobertura plugin of Hudson, but the file is not being created. I've added the following to my POM <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> </plugin> </plugins> </reporting> After running mvn cobertura:cobertura, the HTML site is generated as expected at **\target\site\cobertura, but coverage.xml is nowhere to be found. What am I

Clearing coverage highlighting in Eclipse

别说谁变了你拦得住时间么 提交于 2019-12-02 13:49:55
After running coverage reports in Eclipse (using cobertura or an EMMA plugin), my source code files get highlighted in green, red and yellow depending on which lines of code were covered by tests. How can I clear this highlighting after I'm done? Click the "Remove all Sessions" button in the toolbar of the "Coverage" view. On 4.2 eclipse it seems to be impossible to remove the eCobertura highlights. Sadly eCobertura plugins seems to be not maintained anymore. However if you start writing into the class, its gone. So type a space, and then undo , and its gone. I found a workaround over on