如何对button_click事件进行单元测试 [英] how to unit test a button_click event

查看:94
本文介绍了如何对button_click事件进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分配了对登录页面进行单元测试的任务.我是编程新手,请帮帮我
这是我的代码.我需要在visualstudio中进行单元测试

i have an assignment to unit test a login page. iam new to programming please help me
this is my code. i need to unit test in visualstudio

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            Display();
        }


        private void Display()
        {
            if (textBox1.Text == "admin" && textBox2.Text == "admin")
                MessageBox.Show("login success");
            else
                MessageBox.Show("try again");
        }

推荐答案

嗯,这是一个相当大的问题,涉及如何组合应用程序.恐怕这会很快发展起来.

最大的问题是,单元测试是什么意思?您是在谈论自动化测试,即运行程序和脚本将值放入文本框并按按钮(等等)的过程吗?如果是,那么我建议您使用 NUnitForms [ ^ ]来管理此问题?

但是,如果您正在谈论内部测试逻辑,那么您确实需要大量更改体系结构.由于这是一个非常大的主题,因此除非您指出这是您要采用的方法,否则我不会在这里进行讨论.在这种情况下,我希望您能对此发表评论.
Well, this is a fairly large question and goes to how you have put together your application. I''m afraid this is going to get advanced fairly quickly.

The big question is what do you mean by unit testing? Are you talking about automation testing, whereby you run the program and a script puts values into textboxes and presses buttons (and the like)? If you are, then I would suggest that you use NUnitForms[^] to manage this?

If, however, you are talking about testing the logic internally, then you really need to change the architecture considerably. As that''s a very large topic, I won''t go into it here unless you indicate that this is the approach you want to take - in which case, I''ll expect to see a comment from you to that effect.


朋友,

在上面的代码中,没有要测试的内容.

当您单击按钮时,将调用"Display()"方法.

在显示方法中,他们正在查看用户输入的详细信息.

如果在两个文本框中输入的值是"admin"-显示消息登录成功"

否则登录失败".


问候,
Prasad
Hi Friend,

In Above code nothing is there to test.

when you click on button, "Display()" method will be called.

In Display method they are cheeking the details entered by user.

if Values entered in two text boxes are "admin" - display a message "Login Success"

else "Login failed".


Regards,
Prasad


这篇关于如何对button_click事件进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆