請問,我是Java新手。我怎麼能寫下面的程序的JUnit測試:編寫JUnit測試
程序來測試:
package codekeeper;
/**
*
* @author henryjoseph
*/
import java.util.*;
import java.io.*;
public class CodeKeeper {
ArrayList<String> list; //no specific amount..
String[] codes = {"alpha","lambda","gamma","delta","zeta"};
public CodeKeeper (String[] userCodes)
{
list = new ArrayList<String>();
for(int i =0; i<codes.length;i++)
addCode(codes[i]);
for(int i =0; i<userCodes.length;i++)
addCode(userCodes[i]);
for(String code:list)
System.out.println(code);
}
final void addCode(String code)
{
if(!list.contains(code))
list.add(code);
}
public static void main(String[] args) {
System.out.print("Enter your name and press Enter: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = null;
String[] argu = new String[] {name};
try {
name = br.readLine();
argu = new String[] {name} ;
}catch (IOException e) {
System.out.println("Error!");
System.exit(1);
}
CodeKeeper keeper = new CodeKeeper(argu);
}
}
樣品測試代碼:
public class MyClassTest {
@Test
public void testMultiply() {
MyClass tester = new MyClass();
assertEquals("Result", 50, tester.multiply(10, 5));
}
}
這是寫的標準方法Junit測試?