我想要做的是在运行单元测试时动态创建表单。实际表单只能作为进度条。我的单元测试使用Selenium库测试网站,最好有一些进度条。我试图在测试过程中创建新表单,但是当测试执行时,表单就会挂起。谢谢!
[TestMethod]
public void test1()
{
using(Form1 form=new Form1())
{
form.Show();
form.RunAsync();
}
Assert.IsTrue(doSomeThing());
}
这就是现在的形式。这只是一个例子!后台工作人员应填写进度条,但是,一旦表单显示,它就会冻结
BackgroundWorker bw;
private void RunAsync()
{
bw.RunWorkerAsync();
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
or (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
bw.ReportProgress(i);
}
bw.ReportProgress(100);
}
答案 0 :(得分:0)
这是一个简单的进度条示例
public Form1()
{
InitializeComponent();
backgroundWorker1.DoWork += backgroundWorker1_DoWork_1;
backgroundWorker1.ProgressChanged += backgroundWorker1_ProgressChanged_1;
Load += Form1_Load_1;
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Start the BackgroundWorker.
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress.
backgroundWorker1.ReportProgress(i);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
注意区别:你的后台工作人员做了一些工作并报告,但是没有人抓住它,或者你没有显示你的所有代码。无论如何,你可以拿这个代码