Coder Social home page Coder Social logo

Comments (5)

christ66 avatar christ66 commented on June 28, 2024

It should work without any issues, please read: https://github.com/cobertura/cobertura/wiki/FAQ and search for the Tomcat section.

from cobertura.

hkamran avatar hkamran commented on June 28, 2024

Haha, works. I noticed there is a way to force the cobertura ser file to be written while the server is on, is there a way to clear the cobertura data so I don't have to restart tomcat to get a fresh coverage?

from cobertura.

christ66 avatar christ66 commented on June 28, 2024

There is no safe way to clear the cobertura data. Cobertura data does not get written until jvm shutdown hooks are executed.

There might be a few ways, however that could involve a lot of hacking which I would strongly advise against. However here is the hack. For each class that gets instrumented, we add a method

  public static int[] __cobertura_get_and_reset_counters() {...}

which can be called using reflection. However this will require that you scan every single class loaded in the jvm to see if it contains the method above and invoke it with reflection.

            String className = "Name.Of.Instrumented.Class";
            String methodName = "__cobertura_get_and_reset_counters";
            Class saveClass = Class.forName(className);
            java.lang.reflect.Method saveMethod = saveClass.getDeclaredMethod(
                    methodName, new Class[0]);
            saveMethod.invoke(null, new Object[0]);

Also a try-catch block would need to go around the invoke call just in case the method does not exist. If you can provide a use case where resetting the count could be useful, I could write something for the FlushCoberturaServlet to allow for resetting of all coverage information.

from cobertura.

hkamran avatar hkamran commented on June 28, 2024

We'll we run automated tests and when I do a full run I would love to do a reset on the instrumented files, run tests, dump ser, create report. I'm not to fond of using scripting to do the work of rebooting the server as it leaves the automated tests system dependent.

from cobertura.

christ66 avatar christ66 commented on June 28, 2024

I'm not sure I understand the process you are doing. Are you trying to do the following:

  1. Reset instrumented files
  2. run tests
  3. dump ser
  4. create report

Step 1 is not necessary because cobertura when it initially starts it is at 0 everything. Step 3 can be achieved using the coberturaFlush.war file where you can flush cobertura data at anytime. Also see the FAQ (last part) on how to create your own cobertura flushing part (e.x. when logout button is pressed). We also have a test unit (WebAppFunctionalTest.java) that flushes cobertura information while (in our case a jetty servlet) is still running.

from cobertura.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.