2012-06-17 61 views
0

我是新來的JUnit測試,我有以下的測試 -JUnit的錯誤 - AssertionFailedError異常

public class ItemsTest extends TestCase { 

    private Items itemsd; 

    protected void setUp() throws Exception { 
     super.setUp(); 

     itemsd = new Items(); 

    } 


    @Test 
    public void testGetCategory() { 
     boolean result = itemsd.getCategory() != null; 
     Assert.assertTrue(result); 
    } 

} 

哪些測試這真的很簡單的代碼 -

/** 
* @return Returns the category. 
*/ 
public String getCategory() { 
    return category; 
} 

很顯然,我是缺少在這裏簡單的東西?

+0

測試會更容易些,如果你寫Assert.assertNotNull閱讀( itemsd.getCategory()); –

回答

3

看來你的itemsd.getCategory()回報null

boolean result = itemsd.getCategory() != null; 

resultfalse,所以下面的語句無法斷言

Assert.assertTrue(result); 
+0

哦!哦,今天我很密集 - 謝謝! – Expecto