⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcase.java

📁 软件测试和junit实践一书的源代码
💻 JAVA
字号:
/* * TestCase.java * * Created on 2003年4月18日, 上午9:14 */package com.fastpoint.book;import java.io.*;import java.util.*;/** * * @author  Fastpoint */public abstract class TestCase {        private String _TeseCaseName;    private FileWriter _log;    private Object _OUT;    private int _passTally;    private int _failTally;        /** Creates a new instance of TestCase */    public TestCase() {        String logFileName = "E:\\MyUnitTest\\com\\fastpoint\\Mytester_java.txt";        _TeseCaseName = "TeseCase";        _OUT = null;        _passTally = 0;        _failTally = 0;                try{           _log = new FileWriter(logFileName);        }catch (IOException e){           System.err.println("Could not open File" + logFileName);        }                try{           String line = _TeseCaseName + "\n" + new Date().toString() + "\n";           _log.write(line);        }catch (IOException e){           System.err.println("Error writing to log File");           e.printStackTrace();        }    }        /** Creates a new instance of TestCase */    public TestCase(String logFileName) {        _TeseCaseName = "TeseCase";        _OUT = null;        _passTally = 0;        _failTally = 0;                try{           _log = new FileWriter(logFileName);        }catch (IOException e){           System.err.println("Could not open File" + logFileName);        }                try{           String line = _TeseCaseName + "\n" + new Date().toString() + "\n";           _log.write(line);        }catch (IOException e){           System.err.println("Error writing to log File");           e.printStackTrace();        }    }        /** Creates a new instance of TestCase */    public TestCase(String TeseCaseName,String logFileName) {        _TeseCaseName = TeseCaseName;        _OUT = null;        _passTally = 0;        _failTally = 0;                try{           _log = new FileWriter(logFileName);        }catch (IOException e){           System.err.println("Could not open File" + logFileName);        }                try{           String line = _TeseCaseName + "\n" + new Date().toString() + "\n";           _log.write(line);        }catch (IOException e){           System.err.println("Error writing to log File");           e.printStackTrace();        }    }        public void dispose(){       try{          int total = totalTally();          _log.write("\n");          _log.write("__________________________________________");          _log.write("\n");          _log.write("Summary of results:\n");          _log.write("\t" + total + " test cases run\n");          _log.write("\t" + "Pass:" + passTally() + "\n");          _log.write("\t" + "Fail:" + failTally() + "\n");          _log.close();       }catch (IOException e){          System.err.println("Error writing to log File");          e.printStackTrace();       }    }        public void runAllTestSuites(){       runFunctionalTestSuites();       runInteractionTestSuites();       runConstructTestSuites();    }        public abstract void runFunctionalTestSuites();    public abstract void runInteractionTestSuites();    public abstract void runConstructTestSuites();        public int passTally() { return _passTally; }    public int failTally() { return _failTally; }    public int totalTally(){       return _passTally + _failTally;    }    //    public abstract Lamp newObject(String stat);    public abstract Object newObject();        public void disposeObject() { _OUT = null; }        protected void setObject(Object outptr) { _OUT = outptr; }    public Object getObject() { return _OUT; }    protected void logTestCaseStart(String testID) {       try{          _log.write("\n");          _log.write("__________________________________________");          _log.write("\n");          _log.write("Start test case " + testID + "\n");          _log.flush();       }catch (IOException e){          System.err.println("Error writeing to log File");          e.printStackTrace();       }    }         protected void logTestCaseResult(TestResult result){       if( result == TestResult.Fail ){          ++ _failTally;                    try{            _log.write("\tOUT:" + getObject().toString() + "\n");            _log.flush();          }catch (IOException e){            System.err.println("Error writeing to log File");            e.printStackTrace();          }       } else if ( result == TestResult.Pass){          ++ _passTally;       }              try{          _log.write("RESULT:" + result.toString() + "\n");          _log.flush();       } catch (IOException e) {          System.err.println("Error writeing to log File");          e.printStackTrace();       }    }        protected void logComment(String comment){       try{          _log.write("\t" + comment + "\n");          _log.flush();       } catch (IOException e) {          System.err.println("Error writeing to log File");          e.printStackTrace();       }    }        protected TestResult passOrFail(boolean condition){       if (condition){           return TestResult.Pass;       } else {           return TestResult.Fail;       }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -