📄 testutils.java
字号:
display(" Method : " + tMethod.getMethodName());
display(EMPTY);
display(" Number of tests : " +
tMethod.getTestsNumber());
display(EMPTY);
display(" of which in error : " +
tMethod.getErrorTestsNumber());
display(" in failure : " +
tMethod.getFailureTestsNumber());
display(" successfully : " +
tMethod.getSuccessTestsNumber());
display(EMPTY);
display(" --------------------------------------- ");
display(EMPTY);
}
display(" --------------------------------------- ");
display(" ----- METHODS : TESTS IN FAILURE ------ ");
display(" --------------------------------------- ");
display(EMPTY);
methodsList = tClass.getMethodsFailure();
for (int j = 0; j < methodsList.size(); j++)
{
TestMethod tMethod = (TestMethod) methodsList.get(j);
display(" Method : " + tMethod.getMethodName());
display(EMPTY);
display(" Number of tests : " +
tMethod.getTestsNumber());
display(EMPTY);
display(" of which in error : " +
tMethod.getErrorTestsNumber());
display(" in failure : " +
tMethod.getFailureTestsNumber());
display(" successfully : " +
tMethod.getSuccessTestsNumber());
display(EMPTY);
display(" --------------------------------------- ");
display(EMPTY);
}
display(" --------------------------------------- ");
display(" ----- METHOD : TESTS IN ERROR --------- ");
display(" --------------------------------------- ");
display(EMPTY);
methodsList = tClass.getMethodsError();
for (int j = 0; j < methodsList.size(); j++)
{
TestMethod tMethod = (TestMethod) methodsList.get(j);
display(" Method : " + tMethod.getMethodName());
display(EMPTY);
display(" Number of tests : " +
tMethod.getTestsNumber());
display(EMPTY);
display(" of which in error : " +
tMethod.getErrorTestsNumber());
display(" in failure : " +
tMethod.getFailureTestsNumber());
display(" successfully : " +
tMethod.getSuccessTestsNumber());
display(EMPTY);
display(" --------------------------------------- ");
display(EMPTY);
}
}
/**
* Displays the tests results for the classes.
*/
private void displayClassesStatement()
{
display(EMPTY);
display(" --------------------------------------- ");
display(" ---- CLASSES : SUCCESSFULLY TESTS ----- ");
display(" --------------------------------------- ");
display(EMPTY);
ArrayList classesList = TestResult.getInstance().getSuccessClassTests();
for (int i = 0; i < classesList.size(); i++)
{
TestClass tClass = (TestClass) classesList.get(i);
display("****************************************************");
display(" CLASS : " + tClass.getClassName());
display(EMPTY);
display(" Number of tested methods : " +
tClass.getMethodTestsNumber());
display(EMPTY);
display(" of which in error : " +
tClass.getErrorTestsNumber());
display(" in failure : " +
tClass.getFailureTestsNumber());
display(" successfully : " +
tClass.getSuccessTestsNumber());
display(EMPTY);
displayMethodsStatement(tClass);
display(EMPTY);
display("****************************************************");
display(EMPTY);
}
display(EMPTY);
display(" --------------------------------------- ");
display(" ---- CLASSES : TESTS IN FAILURE ----- ");
display(" --------------------------------------- ");
display(EMPTY);
classesList = TestResult.getInstance().getFailureClassTests();
for (int i = 0; i < classesList.size(); i++)
{
TestClass tClass = (TestClass) classesList.get(i);
display("****************************************************");
display(" CLASS : " + tClass.getClassName());
display(EMPTY);
display(" Number of tested methods : " +
tClass.getMethodTestsNumber());
display(EMPTY);
display(" of which in error : " +
tClass.getErrorTestsNumber());
display(" in failure : " +
tClass.getFailureTestsNumber());
display(" successfully : " +
tClass.getSuccessTestsNumber());
display(EMPTY);
displayMethodsStatement(tClass);
display(EMPTY);
display("****************************************************");
display(EMPTY);
}
display(EMPTY);
display(" --------------------------------------- ");
display(" ---- CLASSES : TESTS IN ERROR ----- ");
display(" --------------------------------------- ");
display(EMPTY);
classesList = TestResult.getInstance().getErrorClassTests();
for (int i = 0; i < classesList.size(); i++)
{
TestClass tClass = (TestClass) classesList.get(i);
display("****************************************************");
display(" CLASS : " + tClass.getClassName());
display(EMPTY);
display(" Number of tested methods : " +
tClass.getMethodTestsNumber());
display(EMPTY);
display(" of which in error : " +
tClass.getErrorTestsNumber());
display(" in failure : " +
tClass.getFailureTestsNumber());
display(" successfully : " +
tClass.getSuccessTestsNumber());
display(EMPTY);
displayMethodsStatement(tClass);
display(EMPTY);
display("****************************************************");
display(EMPTY);
}
}
/**
* Displays the result of the set of tests.
*
* @param name The name of the class that wants to display the result.
*/
public void displayTestStatement(String name)
{
if (TestResult.getInstance().isInitiator(name))
{
StringBuffer sb = new StringBuffer();
display(EMPTY);
sb.append(EMPTY);
display("====================================================");
display("TESTS STATEMENT :");
display("====================================================");
display(EMPTY);
display(" Number of tested classes : " +
TestResult.getInstance().getClassTestsNumber());
display(EMPTY);
display(" of which in error : " +
TestResult.getInstance().getErrorClassTestsNumber());
display(" in failure : " +
TestResult.getInstance().getFailureClassTestsNumber());
display(" successfully : " +
TestResult.getInstance().getSuccessClassTestsNumber());
display(EMPTY);
display(" Number of tested methods : " +
TestResult.getInstance().getMethodTestsNumber());
display(EMPTY);
display(" Number of tests : " +
TestResult.getInstance().getTestsNumber());
display(EMPTY);
displayClassesStatement();
display(EMPTY);
display("====================================================");
display(EMPTY);
display(EMPTY);
}
}
/**
* Creates a file and writes object to it.
*
* @param fileName Name of the File to create. [Mandatory]
* @param filePath Path of the File to create (in windows mode : \\directory\\directory\\ ).
* @param b Array of bytes.
*/
public void createFile(String fileName, String filePath, byte[] b)
{
try
{
displayMsg("createFile fileName : " + fileName);
displayMsg("createFile filePath : " + filePath);
if ((fileName == null) || (fileName.length() < 1))
{
throw new Exception("FileName is not defined");
}
File file;
if (filePath == null)
{
file = new File(fileName);
}
else
{
//file = new File(filePath + fileName);
file = new File(fileName);
}
displayMsg("createFile length of the bytes array : " + b.length);
if (!file.exists())
{
file.createNewFile();
}
FileOutputStream foutstream = new FileOutputStream(file);
foutstream.write(b);
foutstream.close();
}
catch (Exception e)
{
displayMsg("createFile " + e.toString());
}
}
/**
* Reads data from file.
*
* @param fileName Name of the file to be read. [Mandatory]
* @param filePath Path of the file to be read.
*
* @return Read data as a bytes array.
*/
public byte[] readBytesFromFile(String fileName, String filePath)
{
byte[] returnBytes = null;
try
{
displayMsg("readBytesFromFile fileName : " + fileName);
displayMsg("readBytesFromFile filePath : " + filePath);
if ((fileName == null) || (fileName.length() < 1))
{
throw new Exception("FileName is not defined");
}
File file;
if (filePath == null)
{
file = new File(fileName);
}
else
{
file = new File(filePath + fileName);
}
BufferedInputStream bufin = new BufferedInputStream(
TestUtils.class.getClassLoader().getResourceAsStream(filePath + fileName));
List listBytes = new ArrayList();
int b;
int i = 0;
while ((b = bufin.read()) >= 0)
{
listBytes.add(new Byte((byte) b));
i++;
}
bufin.close();
returnBytes = new byte[listBytes.size()];
for (int j = 0; j < listBytes.size(); j++)
{
returnBytes[j] = ((Byte) listBytes.get(j)).byteValue();
}
}
catch (Exception e)
{
displayMsg("readBytesFromFile " + e.toString());
}
return returnBytes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -