English 中文(简体)
How to TDD a JFrame?
原标题:How to TDD a JFrame?

我正在从事一个新项目,我希望在该项目中展示一些有关屏幕的数据。 我决心利用对我来说是新鲜的TDD,但我热爱这一想法,迄今为止,我已经走过了相当的科索沃。

我设立了一个联合阵线,增加了一个文本,并提出了案文,但我如何适当测试这一点? 或者,在TDD背景下的这种错误思维在我方? 我希望(以TDD的方式)确保数据正确显示! 展示案文的<适当包含测试,但 /strong>没有。

这是一个完全简化的例子:

public class MyTextDisplay {
    public static void main(String[] args) {
        JFrame my_frame = new JFrame("DisplaySomeText");
        my_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTextArea textArea = new JTextArea(5, 20);
        textArea.setEditable(false);

        my_frame.add(textArea);
        my_frame.setVisible(true);

        //this would be in a separate method
        textArea.append("Hello World");
    }
}
最佳回答

贸易和发展会议要求你以不同的方式思考问题。 你们首先决定你们将如何测试,在你实际起草解决方案守则之前,你将如何测试。

对德国马克公司来说,这可能会变得很trick,而且,坦率地说,你的德国马克永远不应包含任何可以单独一层的逻辑。 例如,所展示的价值应当来自与全球倡议毫无关系的物体,但可以单独测试。 这使你能够开发独立于显示(概览)的主要业务逻辑(制模和制片)。 这就是MVC模式。 快速发展只是意味着你检验你在撰写法典之前可以做些什么,而随着你增加法典,将开始进行更多的测试。

I d rather focus on my design and ensure that whatever is generating the text value works as expected. The GUI should be "dumb" and only focus on displaying or retrieving values, with little, if any concern for if the displayed values are indeed correct.

由于全球倡议很难用自动化工具(适当测试)进行测试,因此我尽量避免了这一缺陷,并且把我的全球倡议与我的实际应用分开。 然后,你可以一度测试《全球倡议》,确保它展示它所期望的东西,并侧重于商业逻辑,而不必在你不触及《全球倡议》时对《全球倡议》进行连续测试。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...