什么是Java中的测试驱动开发(TDD)以及如何自动化测试用例

什么是Java中的测试驱动开发(TDD)以及如何自动化测试用例,java,eclipse,algorithm,unit-testing,tdd,Java,Eclipse,Algorithm,Unit Testing,Tdd,我们的想法是尝试在遥控器上用0-9、前进、后退和上一个频道按钮找到所需的最小点击次数,以在给定范围内通过给定的频道序列。按下前进或后退按钮时,将自动跳过被阻止的频道 这是我的工作代码(我因为只问问题而没有做家庭作业而多次被人反对,所以我决定用这一个来做一个完整的工作代码。)。如何使用java和eclipse来展示TDD原则,从而自动化it测试用例?Eclipse是我正在使用的编辑器 package Algo; import java.util.*; public cl

我们的想法是尝试在遥控器上用0-9、前进、后退和上一个频道按钮找到所需的最小点击次数,以在给定范围内通过给定的频道序列。按下前进或后退按钮时,将自动跳过被阻止的频道

这是我的工作代码(我因为只问问题而没有做家庭作业而多次被人反对,所以我决定用这一个来做一个完整的工作代码。)。如何使用java和eclipse来展示TDD原则,从而自动化it测试用例?Eclipse是我正在使用的编辑器

    package Algo;

    import java.util.*;

    public class indix {

        public static void main(String args[]) {

            String range;
            String blocked;
            String sequence;
            Scanner in = new Scanner(System.in);
            // Read the Input
            range = in.nextLine();
            blocked = in.nextLine();
            sequence = in.nextLine();

            String blk[] = blocked.split(" ");
            String seq[] = sequence.split(" ");
    //Put the blocked channels into a hash-map
            HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();

            for (int j = 1; j < blk.length ; j++) {
                hm.put(Integer.parseInt(blk[j]), 1);
            }

            String temp[] = range.split(" ");
          //  Start Range and End Range for the channels available from input string 
            int s_range = Integer.parseInt(temp[0]);
            int e_range = Integer.parseInt(temp[1]);
            temp = null;

            for (String s : blk) {
                System.out.print(s + " ");

            }
            System.out.println();
            for (String s : seq) {
                System.out.print(s + " ");
            }
            System.out.println();

                //Initialize a cost array for storing costs as we browse through the sequence
                int[] cost = new int[e_range + 1];

            cost[0] = 0;
    //Curr is the Current channel we are on, next is the channel we want to hop to and diff is the difference in number of channles in between curr and next
            int diff;
            int sum_cost = 0;
            Integer next;
               //Assuming that initially we start with the first channel in the range
                Integer curr = s_range;
            System.out.println("Start, End " + s_range + "," + e_range + " Seq.length "+seq.length);
            for (int i = 1; i < seq.length; i++) {

                    //Assign one by one the channels from the seqeunce in which we want to browse from the sequence list
                        next = Integer.parseInt(seq[i]);
                diff = next - curr;
                System.out.println("Diff = " + diff);
                int start, diff_adj = 0;
                start = curr + 1;


                   //Find out the number of blocked channels which will be auto skipped in between
                while (true) {

                                    if (start == next)
                        break;
                    if (hm.containsKey(start))
                        diff_adj++;
                    start++;

                }

                System.out.println("Diff Adj= " + diff_adj);
    //Adjust the difference with number of blocked channels skipped
                diff = diff - diff_adj;

                System.out.println("Length of current channel is "
                        + seq[i].length());
    //if the differene is greate than the length of the channel, the use the length of channel as the cost, else the diff value(i.e if from 102 to 104 it is easy to press forward button twice rather then pressing 104 which is three buttons. From 102 to 108, it is cheaper to press 108 directly as it costs three lcicks rather than one by one incrementing from 102. Account from skiped channels as you do this.)
                if (diff > seq[i].length())
                    cost[next] = seq[i].length() + cost[curr];
                else
                    cost[next] = diff + cost[curr];
                curr = next;
                System.out.println("The current cost is this channel is" + next
                        + "," + diff);

                sum_cost = cost[next];
            }

            System.out.println("Minimum cost is" + sum_cost);

        }

    }

My output is:

    2 103 108 
    3 102 106 109 
    Start, End 100,200 Seq.length 4
    Diff = 2
    Diff Adj= 0
    Length of current channel is 3
    The current cost is this channel is102,2
    Diff = 4
    Diff Adj= 1
    Length of current channel is 3
    The current cost is this channel is106,3
    Diff = 3
    Diff Adj= 1
    Length of current channel is 3
    The current cost is this channel is109,2
    Minimum cost is7
package算法;
导入java.util.*;
公共类indix{
公共静态void main(字符串参数[]){
字符串范围;
串阻塞;
字符串序列;
扫描仪输入=新扫描仪(系统输入);
//读取输入
范围=in.nextLine();
blocked=in.nextLine();
sequence=in.nextLine();
字符串blk[]=blocked.split(“”);
字符串seq[]=sequence.split(“”);
//将阻塞的通道放入哈希映射
HashMap hm=新的HashMap();
对于(int j=1;jseq[i].length())
成本[下一步]=序号[i]。长度()+成本[当前];
其他的
成本[下一步]=差异+成本[当前];
curr=next;
System.out.println(“当前成本是这个频道是”+next
+“,”+diff);
总成本=成本[下一步];
}
系统输出打印项次(“最低成本为”+总成本);
}
}
我的输出是:
2 103 108 
3 102 106 109 
起点、终点100200序号长度4
差异=2
差异调整=0
当前通道的长度为3
目前的成本是这个渠道是102,2
差异=4
差异调整=1
当前通道的长度为3
目前的成本是这个频道是106,3
差异=3
差异调整=1
当前通道的长度为3
目前的成本是这个渠道是109,2
最低费用是7英镑

当您谈论TDD时,在实际实现它之前,您会考虑所有的场景/测试用例,然后w.r.t您编写测试用例并让它们失败。 通过适当的实施,你一个接一个地让他们通过。()


要执行TDD,您需要工具和框架,当您谈论TDD时,请查找更多信息,然后在实际实施之前考虑所有场景/测试用例,然后编写测试用例并让它们失败。 通过适当的实施,你一个接一个地让他们通过。()


要执行TDD,您需要工具和框架,当您谈论TDD时,请查找更多信息,然后在实际实施之前考虑所有场景/测试用例,然后编写测试用例并让它们失败。 通过适当的实施,你一个接一个地让他们通过。()


要执行TDD,您需要工具和框架,当您谈论TDD时,请查找更多信息,然后在实际实施之前考虑所有场景/测试用例,然后编写测试用例并让它们失败。 你一个接一个地