Getting test coverage results with Cobertura - java

I'm using Cobertura 2.3.0 from http://cobertura.github.io/cobertura/ to analyze my project for test coverage, and I'm getting a
Error: Could not find or load main class net.sourceforge.cobertura.instrument.Main
When trying to execute cobertura-instrument.bat from the command line. I've looked at this batch file and it's trying to load several JARs from the %COBERTURA_HOME%/lib folder that don't exist. I've manually downloaded these JARs but am getting other strange errors.
java.lang.IncompatibleClassChangeError: class net.sourceforge.cobertura.instrument.pass1.DetectIgnoredCodeClassVisitor has interface org.objectweb.asm.ClassVisitor as super class
Is it possible that this release was incorrectly updated? I don't see a way to make this work any other way. Further, does anybody know of a working test-coverage utility, preferably a working different version of Cobertura?
I've tried Nounit and several others, but have not gotten the type of clean output that I know Cobertura can produce.

Answering my own question in hopes it can help somebody.
At time of writing, there is a known bug with Cobertura throwing a ClassNotFoundException in certain circumstances. See the following issue tracker page: https://github.com/cobertura/cobertura/issues/74#issuecomment-41383903
For the time being, I've gone with EclEmma Eclipse plugin for EMMA for my test code coverage, and got nice, pretty results the way I wanted.

Related

Unexpected Format on output of Cucumber HTML Report

Using: Java, IntelliJ Community Edition, Azure DevOps, Ubuntu agent
Goal: To see accurate charted results of tests run either automatically when a pipeline is triggered, manually, or locally if a test is run locally in IDE
Steps so far:
tried in-built vs test as there was tons of documentation on it but it seems that's only for windows agents (and possibly only .net?) neither of which is an option. Link1. Link2.
installed cucumber-html-report app to azure devops
added cucumber dependencies to pom.xml and added the following code main runner
#CucumberOptions(features="classpath:LoginTest.feature", plugin={"pretty", "html:target/cucumber-html-report", "json:target/cucumber.json", "junit:target/cucumber.xml", "rerun:target/rerun.txt"})
tests run and output but when you open the file, there's no formatting (just raw js, html, etc)
I've spent so long on what seems like such a simple task. I suspect it's at least in part due to the fact that I'm still familiarising myself with Cucumber and Azure DevOps so I'm hoping someone will see something I've missed. At this point I've thrown everything I could find on Google at it and nothing has worked successfully. Any and all help is very much appreciated
I got the answer. It was this section:
"html:target/cucumber-html-report",
It was missing the .html at the end which is why I seemed to be following the instructions, getting some output, but not producing the expected result

How can I discover what all jars are on my classpath in Java 11 to resolve a duplicate class issue?

I'm attempting to use VS Code to run some unit tests in my solution. When I do, I get the following error:
java.lang.NoSuchMethodError: 'org.mockito.internal.progress.MockingProgress org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress()'
at org.mockito.ArgumentMatchers.reportMatcher(ArgumentMatchers.java:1330)
at org.mockito.ArgumentMatchers.eq(ArgumentMatchers.java:908)
When I run it using maven, I do not get said error. I have two theories. Either the IDE's test runner pulls in an older version of mockito or one of my test dependencies has some older mockito code embedded in it and somehow I'm getting lucky when running it from maven.
My thought was to print out the class path and see if there was anything unusual. But it appears that the code samples1 I've found on the Internet doesn't seem to work in Java 11. I'm guessing this is due to things changing with the introduction of modules.
So how can I discover what all jars are on my classpath in Java 11 to resolve a duplicate class issue?

How to mark jenkins build failed if JUnit test has an error?

I need a workaround for this Jenkins issue (JUnit report doesn't distinguish between test failures and errors).
I thought of using the Groovy Postbuild Plugin but it looks like this Jenkins "philosophy" is deeply integrated, i.e. TestResultAction doesn't even provide the tests in error.
Any other ideas?
Well, for a work around I think that you can create simple script for parsing xunit file and in case find error use exit 1 for mark build failed. Look in the similar ticket

UIAutomator error when runnging tests

I am having big problemes with the uiautomator from google. I have a S3 not rooted and I can't run my tests on the device.
Error:
INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=com.test1.test
INSTRUMENTATION_CODE: 0
I saw some answers that pointed me to root the phone. I do not want to do that.
Please give me some answers how to use the tests.
I was having this same issue! I'm not 100% sure why it was happening, but I think it has to do with the way ant builds the JAR file. When I first started writing my uiautomation tests, I put them in the same project as some JUnit tests, which were in separate packages (one for the source classes and one for the tests). I created my uiautomation tests in the test package, and when I went to build and run them, I got an error that my test classes weren't being found.
I believe this was because the JAR file only included the source package and not the test package. So, I made a new project and put my uiautomation tests in a single source package, built the project, and pushed the JAR to my device. They ran smoothly after that!
I'm pretty new to this stuff too, so I'm not entirely sure if that answers your question. An alternative solution might be to move the UIA tests to the source package instead of creating a whole new project.
Also, Google's resources are really good for getting a basic feel for setting up and using uiautomation (if you haven't checked them out already). If you really can't find a fix, I'd recommend copying and pasting their demo into a fresh project and trying to get that to run: http://developer.android.com/tools/testing/testing_ui.html

Spurious NoSuchMethodError

Been getting a NoSuchMethodError on one of our classes on a simple getter method. The odd thing is that we can debug the code and see the error occur in the debugger (by stepping over the relevant line), however we can also use the IDE (IntelliJ IDEA) to see the method does exist.
Doing xxxx.getYYY() evaluates fine through the IDE expression evaluator. And going xxxx.getClass().getMethods() we can see the getYYY() method in the list. We have tried cleaning out all the built files, IDE output directories, IDE caches, rebooting etc and nothing seems to help.
I would understand a NoSuchMethodError would be happening if we had compiled against something but then a different Jar/class was being found at runtime. But that doesn't explain to me why, at runtime while debugging to the line in question, we can see the method is there, but stepping over the line throws the Exception.
Tried reproducing on another machine but it does not reproduce.
Does anyone have any insight into what could be happening here?
Most likely you are not running the same versions of code in IntelliJ as what you are editing. I get this problem often with lots of maven projects open at once with different versions in dependencies to what I am editing. IntelliJ can get confused (or I get confused as to which version I am actually running)
NoSuchMethodError - This mostly occurs at runtime. I came across this error, the reason was incompatible versions of asm and cglib libraries in my classpath.
The asm and cglib libraries are used by many frameworks like hibernate, spring, hadoop for runtime byte code manipulation.
Classloader always refers to the first version of the jar on the classpath.

Categories