最近我開始使用DbUnit,我正在嘗試編寫一個非常簡單的集成測試,只是爲了填充3行的表。閱讀DbUnit Getting Started Guide,它告訴我創建一個數據集文件。我的數據集xml文件看起來就像這樣:JUnit + DbUnit - 擴展時未找到測試DatabaseTestCase
<dataset>
<notaFiscal cliente="Cliente 1" valor="26.5" data='2016-04-04'/>
<notaFiscal cliente="Cliente 2" valor="30.5" data='2016-05-01'/>
<notaFiscal cliente="Cliente 3" valor="28.2" data='2015-08-11'/>
</dataset>
然後,我要創建延伸DBTestCase
測試類並實現我的測試方法(與@Test
註釋,就像任何其他JUnit測試案例)。我創建的類如下:
public class GerenciadorNFTest extends DBTestCase {
private GerenciadorNotaFiscal gerenciador = new GerenciadorNotaFiscal();
public GerenciadorNFTest(String name)
{
super(name);
// PBJDT is an abbreviation of PropertiesBasedJdbcDatabaseTester
// just for a better visualization
System.setProperty(PBJDT.DBUNIT_DRIVER_CLASS,
"org.postgresql.Driver");
System.setProperty(PBJDT.DBUNIT_CONNECTION_URL,
"jdbc:postgresql://localhost:5432/dbunit");
System.setProperty(PBJDT.DBUNIT_USERNAME, "postgres");
System.setProperty(PBJDT.DBUNIT_PASSWORD, "123456");
}
protected IDataSet getDataSet() throws Exception {
IDataSet dataSet = new FlatXmlDataSetBuilder().build(
new FileInputStream("notas_fiscais.xml"));
return dataSet;
}
@Test
public void geraPedido() {
Pedido p = new Pedido("Diogo", 26d, 5);
gerenciador.gera(p);
NotaFiscal notaFiscal = gerenciador.recupera("Diogo");
Assert.assertEquals(notaFiscal.getCliente(), "Diogo");
}
}
在那之後,我試圖運行測試用例,但得到了以下錯誤:
junit.framework.AssertionFailedError: No tests found in teste.GerenciadorNFTest
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:227)
如果我試圖刪除extend DBTestCase
,JUnit的識別測試情況下,並正常運行,但延長它沒有。我試圖清理並重新編譯,但沒有奏效。我也嘗試在我使用的IDE之外運行測試(Intellij Idea),但是我又沒有成功。
有沒有人經歷過同樣的問題? 非常感謝您提前。任何幫助將不勝感激。
謝謝!它使用了一個IDatabaseTester。 :) –