标签:接口 unittest 分支 条件 func lte ret info 一个
https://github.com/software-Testing-1506/softwareTesting
个人负责输出接口以及文件操作及文件名筛选部分的实现,为达到松散耦合的编码目的,我们小组对数据进行封装然后在不同接口间传输。
白盒测试的测试方法有代码检查法、静态结构分析法、静态质量度量法、逻辑覆盖法、基本路径测试法、域测试、符号测试、路径覆盖和程序变异。 白盒测试法的覆盖标准有逻辑覆盖、循环覆盖和基本路径测试。其中逻辑覆盖包括语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、条件组合覆盖和路径覆盖。六种覆盖标准发现错误的能力呈由弱到强的变化:
然而遗憾的是我负责的部分对白盒测试 不太适合
为了学习, 我特意去测试了一下输入控制模块 如下:
对于输出可暂且划为四个等价类
@Test
public void testPrint1() {
String s = "asdf";
String filename = "output.txt";
ArrayList<String> as = new ArrayList<String>();
as.add(s);
ArrayList<outfile> ao = new ArrayList<outfile>();
ao.add(new outfile(new File(filename),s));
javarestore.print(as,ao);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename), s);
}
@Test
public void testPrint2() {
String s = "asdf";
String filename = "output.txt";
ArrayList<String> as = new ArrayList<String>();
as.add(s);
ArrayList<outfile> ao = new ArrayList<outfile>();
ao.add(new outfile(new File(filename),s));
javarestore.print(as,ao);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename), s);
}
@Test
public void testPrint3() {
String s = "asdf"; //simulate two files output
String filename = "output.txt";
ArrayList<String> as = new ArrayList<String>();
ArrayList<outfile> ao = new ArrayList<outfile>();
as.add(s);
ao.add(new outfile(new File(filename),s));
String s1 = "xzvbfwetyt";
String filename1 = "output.tt";
as.add(s1);
ao.add(new outfile(new File(filename1),s1));
javarestore.print(as,ao);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename), s);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename1), s1);
}
@Test
public void testPrint4() {
String s = "asdf"; //simulate two files output
String filename = "output.txt";
ArrayList<String> as = new ArrayList<String>();
ArrayList<outfile> ao = new ArrayList<outfile>();
as.add(s);
ao.add(new outfile(new File(filename),s));
String s1 = "xzvbfwetyt";
String filename1 = "output.tt";
as.add(s1);
ao.add(new outfile(new File(filename1),s1));
String s2 = "safgsfghtr";
as.add(s2);
String filename2 = "junittest";
ao.add(new outfile(new File(filename2),s2));
javarestore.print(as,ao);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename), s);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename1), s1);
Assert.assertEquals("output to files but the content of files not match", javarestore.readFileByChars(filename2), s2);
}
@Test
public void testfileopen() {
String filename = "output.txt";
String testcontent = "it‘s a tricking content test checking if the function is right";
try {
javarestore.writeFileByChars(new File(filename), testcontent);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("not fit traversal dir filenames",javarestore.readFileByChars(filename),testcontent);
}
@Test
public void testTraversalDirWithSuffix1() {
String filesuffix = ".cpp";
String[] filenames = {"asd.cpp"};
int count=0;
Assert.assertEquals("not fit ames‘num",javarestore.TraversalDir(filesuffix).length,filenames.length);
for(String s:javarestore.TraversalDir(filesuffix)) {
Assert.assertEquals("not fit traversal dir filenames",s,filenames[count]);
count+=1;
}
}
@Test
public void testTraversalDirWithSuffix2() {
String filesuffix = ".c";
String[] filenames = {"a.c","x.c"};
int count=0;
Assert.assertEquals("not fit ames‘num",javarestore.TraversalDir(filesuffix).length,filenames.length);
for(String s:javarestore.TraversalDir(filesuffix)) {
Assert.assertEquals("not fit traversal dir filenames",s,filenames[count]);
count+=1;
}
}
@Test
public void testTraversalDirWithSuffix3() {
String filesuffix = ".tt";
String[] filenames = {"output.tt"};
int count=0;
Assert.assertEquals("not fit ames‘num",javarestore.TraversalDir(filesuffix).length,filenames.length);
for(String s:javarestore.TraversalDir(filesuffix)) {
Assert.assertEquals("not fit traversal dir filenames",s,filenames[count]);
count+=1;
}
}
@Test
public void testTraversalDirWithSuffix4() {
String filesuffix = ".txt";
String[] filenames = {"output.txt"};
int count=0;
Assert.assertEquals("not fit ames‘num",javarestore.TraversalDir(filesuffix).length,filenames.length);
for(String s:javarestore.TraversalDir(filesuffix)) {
Assert.assertEquals("not fit traversal dir filenames",s,filenames[count]);
count+=1;
}
}
@Test
public void testTraversalDirWithSuffix5() {
String filesuffix = ".classpath";
String[] filenames = {".classpath"};
int count=0;
Assert.assertEquals("not fit ames‘num",javarestore.TraversalDir(filesuffix).length,filenames.length);
for(String s:javarestore.TraversalDir(filesuffix)) {
Assert.assertEquals("not fit traversal dir filenames",s,filenames[count]);
count+=1;
}
}
@Test
public void testTraversalDir() { //ide explain * as all the filenames but the
String[] filenames = {".classpath",".project","a.c","asd.cpp","checkword","javaforcednote","output","output.tt","output.txt","stoplist","text","x.c"};
int count=0;
Assert.assertEquals("not fit traversal dir filenames‘num",javarestore.TraversalDir().length,javarestore.TraversalDir().length);
for(String s:javarestore.TraversalDir()) {
Assert.assertEquals("not fit traversal dir filenames",s,filenames[count]);
count+=1;
}
}
标签:接口 unittest 分支 条件 func lte ret info 一个
原文地址:https://www.cnblogs.com/simonsqd/p/8745444.html