示例配置文件类

此示例文件概述代码覆盖率插件的所有必要方法、导入和实施。

//Add the library scc.jar to your classpath as it contains the interfaces that
//must be extended. The JAR file can be found in the lib directory of the Test 
//Manager installation directory. 
//
//make sure to include these imports after adding the scc.jar external reference
import com.segue.scc.published.api.codeanalysis.CodeAnalysisProfile;
import com.segue.scc.published.api.codeanalysis.CodeAnalysisProfileException;
import com.segue.scc.published.api.codeanalysis.CodeAnalysisResult;

public class myProfileClass implements CodeAnalysisProfile{

  // This function is called first by the Silk Central Code Coverage framework
  // The name of the plug-in is displayed in the code coverage drop down in Silk Central 
  @Override
  public String getName() {
    // The name of the plugin cannot be an empty string
    return "my plugin name";
  }
  
  // This function is called before starting coverage, 
  // this should return all of the objects to be covered and needs to be 
  // converted into xml using the format specified in the XML schema 
  // CodeCoverage.xsd included in the CA-Framework installation folder.
  // This is triggered by the Silk Central Execution Server starting a test run
  // to start code analysis.
  @Override
  public CodeAnalysisResult getBaseline() throws CodeAnalysisProfileException {
    CodeAnalysisResult result = new CodeAnalysisResult();
    try{
      String baselineData = MyCodeCoverageTool.getAllCoveredObjectsData();
      String xmlString = xmltransformXML(baselineData);
      result.Xml(xmlString);
      String myCustomLogMessage = "Code Coverage baseline successfully retrieved.";
      result.AddLogMsg(myCustomLogMessage);
    }catch(Exception e){
      throw new CodeAnalysisProfileException(e); 
    }
    return result;
  }
 
  //This function is called by the Silk Central Code Coverage Framework after the getBaseLine() method is complete
  //this is where you should start my code coverage tool 
  //collecting code coverage data 
  

  @Override
  public boolean startCoverage() throws CodeAnalysisProfileException {
    try{
      MyCodeCoverageTool.StartCollectingCoverageData();
    }catch(Exception e){
      throw new CodeAnalysisProfileException(e); 
    }
  }
  //This function is called after startCoverage,
  //This is triggered by the Silk Central Execution Server finishing a test run
  //to stop code analysis
  //Call to my code coverage tool to stop collecting data here. 
  @Override
  public boolean stopCoverage() throws CodeAnalysisProfileException {
    try{
      MyCodeCoverageTool.StopCollectingCoverageData();      
    }catch(Exception e){
      throw new CodeAnalysisProfileException(e); 
    }
  }
  // This function is called after stopCoverage(), 
  // and should return all the coverage data collected and needs to be 
  // converted into xml using the format specified in the XML schema 
  // CCoverage.xsd included in the CA-Framework installation folder
  
  @Override
  public CodeAnalysisResult getCoverage() throws CodeAnalysisProfileException {
    CodeAnalysisResult result = new CodeAnalysisResult();
    try{
      String coverageData = MyCodeCoverageTool.getActualCoverageData();
      String xmlString = xmltransformXML(coverageData);
      result.Xml(xmlString);
      String myCustomLogMessage = "Code Coverage successfully retrieved.";
      result.AddLogMsg(myCustomLogMessage);
    }catch(Exception e){
     throw new CodeAnalysisProfileException(e); 
    }
    
    return result;
  }
  
  private String transformXML(String myData){
    //code to transform from my data to the Silk CentralM needed xml 
    ...
    return xmlString; 
  }

}