【问题标题】:Fest running speed巨星运行速度
【发布时间】:2015-03-02 09:42:31
【问题描述】:

我正在尝试为基于 swing 的应用程序选择一个 Gui 测试框架工具。 我开始查看 FEST 并创建了一个 Demo 程序来检查运行时间有多快。

我的演示程序(下面的代码)大约需要 85000 毫秒才能完成,这对我来说似乎很慢。

所以我的问题是 Fest 的正常速度吗?

public class DemoGui extends JFrame
{
    private JPanel contentPane;
    private JTextField textField;
    private JPanel panel;
    private JButton btnNewButton;
    private JButton btnRun;

    public static final int REPEAT = 10;

    public static void runX(final JFrame window)
    {
        final FrameFixture main = new FrameFixture(window);

        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                final long start = System.currentTimeMillis();
                for (int i = 0; i < REPEAT; i++)
                {
                    main.textBox().deleteText().setText("this is a test demo");
                    main.button(JButtonMatcher.withText("OK")).click();
                }
                final long end = System.currentTimeMillis();
                System.out.println("Exec Time : " + String.valueOf(end - start));

            }
        }).start();
    }


    public static void main(String[] args)
    {
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                try
                {
                    DemoGui frame = new DemoGui();
                    frame.setVisible(true);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public DemoGui()
    {
        setTitle("DemoGui");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        textField = new JTextField();
        contentPane.add(textField, BorderLayout.NORTH);
        textField.setColumns(10);

        panel = new JPanel();
        contentPane.add(panel, BorderLayout.SOUTH);

        btnRun = new JButton("run");
        btnRun.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                runX(DemoGui.this);
            }
        });
        panel.add(btnRun);

        btnNewButton = new JButton("OK");
        panel.add(btnNewButton);
    }
}

【问题讨论】:

    标签: java swing testing fest


    【解决方案1】:

    fixture 有一个 settings() 函数,它返回存储延迟时间的 Settings 对象。

    将该时间更改为更合适的值:

    public static void main(String[] args)
    {
        main.settings().idleTimeout(2000);
    

    FEST 似乎在等待 JVM 上的所有处理完成后才能进行下一步测试。

    此设置是在不等待所有内容停止的情况下尝试下一步的超时时间(在我的情况下它永远不会停止,我不知道为什么)。所以 FEST 总是属于 timeout 子句,默认为 10000ms(或 10s)。

    您必须在设置中找出每种操作类型的值。

    这取决于你的硬件和你的程序计算的东西的数量。

    注意:我代码中的main.settings()指的是你的final FrameFixture main,而不是main方法。

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      相关资源
      最近更新 更多