问题描述
我目前只会写assertEquals的测试;现有一个窗口,想写测试,不止如何下手,请高手指点;packagebook;importjava.awt.event.*;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.awt.Color;importjava.awt.Container;importjava.awt.Dimension;importjava.awt.Toolkit;importjavax.swing.*;importjava.awt.*;classLoginextendsJFrameimplementsActionListener{Containercp=null;JFramef=null;JButtonj1,j2;JTextFieldt1;JPasswordFieldt2;JLabeljlabel1,jlabel2;Colorc;JPaneljp1,jp2;Login(){f=newJFrame("小型图书管理系统");j1=newJButton("确定");j2=newJButton("取消");cp=f.getContentPane();jlabel1=newJLabel("输入用户名");jlabel2=newJLabel("用户密码");jp1=newJPanel();jp2=newJPanel();t1=newJTextField(18);t2=newJPasswordField(18);jp1.add(jlabel1);jp1.add(t1);jp1.add(jlabel2);jp1.add(t2);JLabelJL=newJLabel("<html><fontcolor=#cc00ffsize='7'><i>欢迎登录"+"</i></font>",SwingConstants.CENTER);cp.add(JL,"North");jp2.add(j1);jp2.add(j2);cp.add(jp1,"Center");cp.add("South",jp2);jp1.setBackground(newColor(255,153,255));Toolkitkit=Toolkit.getDefaultToolkit();Dimensionscreen=kit.getScreenSize();intx=screen.width;inty=screen.height;f.setSize(300,300);intxcenter=(x-300)/2;intycenter=(y-300)/2;f.setLocation(xcenter,ycenter);//显示在窗口中央f.setVisible(true);//------------------------------------------------------------------j1.addActionListener((ActionListener)this);//注册事件监听器j2.addActionListener((ActionListener)this);f.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}publicvoidconfirm(){try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!");}try{Connectioncon=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/test","root","root");Statementsql=con.createStatement();Stringuname=t1.getText().trim();StringMima=t2.getText().trim();StringqueryMima="select*fromuserwherename='"+uname+"'andpassword='"+Mima+"'";ResultSetrs=sql.executeQuery(queryMima);//System.out.print("!!!");if(rs.next()){System.out.print("!!!");newBook("");f.hide();con.close();}else{JOptionPane.showMessageDialog(null,"该用户不存在","提示!",JOptionPane.YES_NO_OPTION);}t1.setText("");t2.setText("");}catch(SQLExceptiong){System.out.println("ECode"+g.getErrorCode());System.out.println("EM"+g.getMessage());}}publicvoidactionPerformed(ActionEvente){Stringcmd=e.getActionCommand();if(cmd.equals("确定")){confirm();}elseif(cmd.equals("取消")){f.dispose();}}}
解决方案
解决方案二:
《TDD测试驱动开发》
解决方案三:
能否详细点,急用