日期:2014-05-20  浏览次数:20817 次

谁会TestDriven.net或NUint啊,断言及使用问题!!!
没找到单元测试论坛,只好在这里发了。
拿了个程序想试试TestDriven的用法,在form用4个TEXT传long型值;1个button发生事件调用,但是有如下问题:
1.在TestFixture外Run Test会提示0pass,0fail,1skipped,是因为Test时我没有调出页面传值,对吗?但是我在方法内赋值4个long型再Test还是同样结果,为什么?
2.从main()前Run Test顺利弹出form,输入数值后,output中并没有expected和actual值的比较,也就是两个Accert.Artequal没有执行,为什么?
3.Ad-Hoc测试应该是可以直接测return返回值并显示在output中,Test不是不能针对非public和void的吗?
4.从单元测试角度,还应该测试哪里?我现在只设计了除For循环外路径的用例。
如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NUnit.Framework;

namespace WindowsApplication2
{
  [TestFixture]
  public partial class Form1 : Form
  {
  //long synokngk = 0; long hokenryou = 0; long kaigohokenryou = 0; long koureihokenryou = 0;//将属性写在方法内内部赋值也显示1 skipped
  public Form1()
  {
  InitializeComponent();
  }

  private void label1_Click(object sender, EventArgs e)
  {

  }

  private void Form1_Load(object sender, EventArgs e)
  {
   
  }

  #region
  [Test]
   
  public void Gethokenryou(long synokngk , long hokenryou , long kaigohokenryou , long koureihokenryou)//这里原来是private long[],按要求改为public void,同时下面的return全部都被注释掉
  {
  try
  {
  long[] hoken = new long[3];
  hoken[0] = 0;
  hoken[1] = 0;
  hoken[2] = 0;
  if (hokenryou == 0 && kaigohokenryou == 0 && koureihokenryou == 0) 
  {
  hoken[0] = synokngk;
  hoken[1] = 0;
  hoken[2] = 0;
  //return hoken;
  Assert.AreEqual(3, hoken[0]);//此断言没有执行
  //Assert.AreEqual(2, hoken[1]);
  //Assert.AreEqual(3, hoken[2]);
   
  }
  if (synokngk < 0)  
  {
  synokngk = synokngk * -1;
  if (hokenryou <= 0 && kaigohokenryou <= 0 && koureihokenryou <= 0)  
  {
  hokenryou = hokenryou * -1;
  kaigohokenryou = kaigohokenryou * -1;
  koureihokenryou = koureihokenryou * -1;
  }
  else
  {
  if (hokenryou < 0)
  {
  hokenryou = 0;
  }
  if (kaigohokenryou < 0)
  {
  kaigohokenryou = 0;
  }
  if (koureihokenryou < 0)
  {
  koureihokenryou = 0;
  }
  }
  for (; synokngk > 0; )
  {
  if (synokngk >= hokenryou)
  {
  hoken[0] += hokenryou;
  synokngk = synokngk - hokenryou;
  }