2015-06-14 36 views
0

試圖使用FEST來測試我的GUI,但我在嘗試訪問包含在自定義JPanel(TopPanel extends JPanel)中的組件時出現問題。所以下面的代碼在嘗試引用作爲MainJFrame中字段存在的「topPane」時失敗。我在這裏做錯了什麼?Java Swing GUI測試巨星JPanel燈具錯誤

public class StableAppsUITest { 

    private FrameFixture window; 
    private JPanelFixture contentFixture; 

    @Before 
    public void setUp() { 
     //Assumes the main class is named "Anagrams" and extends JFrame: 
     window = new FrameFixture(new MainJFrame("Title")); 
     window.show(); 
     contentFixture = window.panel("topPanel"); 

    } 

    @Test 
    public void shouldEnterAnagramAndReturnTrue() { 

     // contentFixture.textBox("mUrlInputTextField").enterText("www.google.com"); 
    } 

    @After 
    public void tearDown() { 
     window.cleanUp(); 
    } 

} 

而這裏的堆棧跟蹤,如果它的hepful:

無法找到使用匹配 org.fest.swing.core.NameAndTypeMatcher [名稱=組件 'topPanel', 型=的javax .swing.JPanel,requireShowing = true]。

組件層次結構:myapp.ui.MainJFrame [名= '幀0',標題= 'MYAPP', 啓用=真,可見=真,表示=真] javax.swing.JRootPane中[] javax.swing中。 JPanel [name ='null.glassPane'] javax.swing.JLayeredPane [] javax.swing.JPanel [name ='null.contentPane'] myapp.ui.TopPanel [name = null] javax.swing.JLabel [name = null,text ='輸入Url:',enabled = true,visible = true,showing = true]javax.swing.JTextField [name = null,text ='',enabled = true,visible = true,顯示= true] javax.swing.JButton [name = null,text ='Submit',enabled = true,visible = true,showing = true] myapp.ui.ContentPanel [name = nu ] javax.swing.JScrollPane [name = null,enabled = true,visible = true,showing = true] javax.swing.JViewport [,1,1,381x270,layout = javax.swing.ViewportLayout,alignmentX = 0.0, alignmentY = 0.0,border =,flags = 25165832,maximumSize =,minimumSize =,preferredSize =,isViewSizeSet = true,lastPaintPosition = java.awt.Point [x = 0,y = 0],scrollUnderway = false] javax.swing。 JList [name = null,selectedValues = [],contents = [],selectionMode = MULTIPLE_INTERVAL_SELECTION,enabled = true, visible = true,showing = true] javax.swing.CellRendererPane [,0,0,0x0,hidden] javax.swing.JScrollPane $ ScrollBar [name = null,value = 0,blockIncrement = 10,minimum = 0,maximum = 270,enabled = true, visible = false,showing = false] javax.swing.plaf.metal。 MetalScrollButton [name = null,text ='',en javax.swing.plaf.metal.MetalScrollButton [name = null,text ='',enabled = true,visible = true,showing = false] javax.swing.JScrollPane $ ScrollBar [name = null,value = 0,blockIncrement = 10,minimum = 0,maximum = 381,enabled = true, visible = false,showing = false] javax.swing.plaf.metal.MetalScrollButton [name = null ,text ='',enabled = true,visible = true,shown = false] javax.swing.plaf.metal.MetalScrollButton [name = null,text ='',enabled = true,visible = true,showing = false] javax.swing.JLabel [name = null,text ='Status:',enabled = true,visible = true,showing = true] javax.swing.JLabel [name = null] javax.swing.JLabel [name = null,text ='',enabled = true,visible = true,showing = true]

在 org.fest.swing.core.BasicComponentFinder.componentNotFound(BasicComponentFinder.java:184) 在 org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder org.fest.swing.exception.ComponentLookupException。的java:169) 在 org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:158) 在 org.fest.swing.core.BasicComponentFinder.findByName(BasicComponentFinder.java:136) 在 有機.fest.swing.fixture.ContainerFixture.findByName(ContainerFixture。Java的:822) 在 org.fest.swing.fixture.ContainerFixture.panel(ContainerFixture.java:406) 在myapp.ui.myappUITest.setUp(myappUITest.java:32)

回答

1

看着你stacktrace,有一個類型爲myapp.ui.TopPanel的組件,但名稱爲空(myapp.ui.TopPanel [name = null])。

window.panel("topPanel")將搜索名爲「topPanel」的JPanel,因此您需要使用mTopPanel.setName("topPanel");來設置組件的名稱,或者使用匹配器來代替。

+0

是的,你是對的。忘了回答我的問題。不過謝謝你。這就是我所缺少的: mTopPanel.setName(「topPanel」); 請您將這行代碼添加到您的答案。我想我也需要編輯我的問題,它缺少一些代碼。雖然沒有它,但你很冷靜。 :) – hadez30