All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.coverage.Metrics Maven / Gradle / Ivy

Go to download

JMockit Coverage is a code coverage tool with several metrics (line, path, data) capable of generating HTML reports. It is designed with ease of use in mind, avoiding the need for complex configuration. Instead, smart (but overridable) defaults are employed, such as the selection of which classes to consider for coverage, and where to find sources files for report generation.

There is a newer version: 1.23
Show newest version
/*
 * Copyright (c) 2006-2014 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.coverage;

import org.jetbrains.annotations.*;

import mockit.coverage.standalone.*;

public enum Metrics
{
   LineCoverage(
      "Line", "Line segments",
      "Measures how much of the executable production code was exercised by tests.\r\n" +
      "An executable line of code contains one or more executable segments.\r\n" +
      "The percentages are calculated as 100*NE/NS, where NS is the number of segments and NE the number of " +
      "executed segments.",
      isActive("line")),

   PathCoverage(
      "Path", "Paths",
      "Measures how many of the possible execution paths through method/constructor bodies were actually " +
      "executed by tests.\r\n" +
      "The percentages are calculated as 100*NPE/NP, where NP is the number of possible paths and NPE the " +
      "number of fully executed paths.",
      isActive("path")),

   DataCoverage(
      "Data", "Fields",
      "Measures how many of the instance and static non-final fields were fully exercised by the test run.\r\n" +
      "To be fully exercised, a field must have the last value assigned to it read by at least one test.\r\n" +
      "The percentages are calculated as 100*NFE/NF, where NF is the number of non-final fields and NFE the " +
      "number of fully exercised fields.",
      Startup.isTestRun() && Startup.isJMockitAvailable() && isActive("data"));

   private static boolean isActive(@NotNull String name)
   {
      String metrics = Configuration.getProperty("metrics", "line");
      boolean all = "all".equals(metrics);
      return all || metrics.contains(name);
   }

   @NotNull private final String name;
   @NotNull public final String itemName;
   @NotNull public final String htmlDescription;
   public final boolean active;

   Metrics(@NotNull String name, @NotNull String itemName, @NotNull String htmlDescription, boolean active)
   {
      this.name = name;
      this.itemName = itemName;
      this.htmlDescription = htmlDescription;
      this.active = active;
   }

   @Override public String toString() { return name; }

   public interface Action { void perform(@NotNull Metrics metric); }

   public static void performAction(@NotNull Action action)
   {
      for (Metrics metric : values()) {
         if (metric.active) {
            action.perform(metric);
         }
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy