why the main method are not covered? urgent, please help me

Posted by Mike.Huang on Stack Overflow See other posts from Stack Overflow or by Mike.Huang
Published on 2010-06-14T09:01:00Z Indexed on 2010/06/14 9:02 UTC
Read the original article Hit count: 264

Filed under:
|

main method:

 public static void main(String[] args) throws Exception
{
    if (args.length != EXPECTED_NUMBER_OF_ARGUMENTS)
    {
        System.err.println("Usage - java XFRCompiler ConfigXML PackageXML XFR");
    }

    String configXML = args[0];
    String packageXML = args[1];
    String xfr = args[2];

    AutoConfigCompiler compiler = new AutoConfigCompiler();
    compiler.setConfigDocument(loadDocument(configXML));
    compiler.setPackageInfoDoc(loadDocument(packageXML));
    // compiler.setVisiblityDoc(loadDocument("VisibilityFilter.xml"));
    compiler.compileModel(xfr);     

}

private static Document loadDocument(String fileName) throws Exception
{
    TXDOMParser parser = (TXDOMParser) ParserFactory.makeParser(TXDOMParser.class.getName());
    InputSource source = new InputSource(new FileInputStream(fileName));
    parser.parse(source);
    return parser.getDocument();  

}

testcase:

@Test

public void testCompileModel() throws Exception { // construct parameters URL configFile = Thread.currentThread().getContextClassLoader().getResource("Ford_2008_Mustang_Config.xml"); URL packageFile = Thread.currentThread().getContextClassLoader().getResource("Ford_2008_Mustang_Package.xml"); File tmpFile = new File("Ford_2008_Mustang_tmp.xfr"); if(!tmpFile.exists()) { tmpFile.createNewFile(); }

String[] args = new String[]{configFile.getPath(),packageFile.getPath(),tmpFile.getPath()};

try { // test main method XFRCompiler.main(args); } catch (Exception e) { assertTrue(true); } try { // test args length is less than 3 XFRCompiler.main(new String[]{"",""}); } catch (Exception e) { assertTrue(true); } tmpFile.delete(); }

coverage outputs displayed as the lines from “String configXML = args[0];" in main method are not covered

© Stack Overflow or respective owner

Related posts about java

Related posts about coverage