0
我正在嘗試爲生成GUI組件的代碼進行單元測試。爲什麼我的單元測試不包括gui組件生成代碼?
這是我的測試代碼。
@Test
public void testMainFrame() {
mFrame = new MainFrame();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
fail("MainFrame Test Fail");
}
assertTrue(true);
}
而目標代碼在這裏。
public MainFrame() {
super("Title");
/* Main page */
clayout = new CardLayout();
headerPane = new JPanel(clayout);
statusField = new JTextArea("TEST TEXT!!!");
statusField.setEditable(false);
headerPane.add(statusField);
startButton = new JButton("Start");
closeButton = new JButton("Close");
startButton.addActionListener(this);
closeButton.addActionListener(this);
this.setLayout(new BorderLayout());
this.setSize(500, 400);
headerPane.setPreferredSize(new Dimension(500, 50));
mainPane = new JPanel();
mainPane.setLayout(new BorderLayout());
mainPane.add(headerPane, BorderLayout.NORTH);
this.setVisible(true);
}
正如您在上面看到的,測試的目標只是生成GUI組件。
我想知道的是,我的測試只包含第一行super("Title");
。
由於這個原因,我的代碼覆蓋率大大降低了。
我可以在聲納報告中看到這個結果。
爲什麼我的測試不包括左代碼?