我正在做一個特殊的junit測試,參數是由用戶在應用程序的前端引入並在應用程序的後端接收的。我想生成使用該信息作爲參數的junit測試。Java將參數動態地傳遞給junit測試
我看到一些指南(如mykong指南和教程點),但其中大多數使用靜態參數化,我想要一些動態的東西。我已經嘗試過使用junit註釋,做一組或將參數傳遞給junit類,使用mockito方法但沒有將其作爲動態過程工作
有人可以指向正確的方向嗎?
現在我有類似的東西
public void run (Object foo) //Class that contains the information introduced by the user
JUnitCore junit1 = new JUnitCore();
Result result4 = JUnitCore.runClasses(GeneratedTest.getClass()); //Junit class
//I tried: do a setFoo on the GeneratedTest ; pass the foo on the constructor;
for (Failure failure : result4.getFailures()) {
System.out.println(failure.toString());
}
動態測試可以用「測試工廠」構建 - https://dzone.com/articles/junit-5-dynamic-tests-generate-tests-at-run-time –
您正在搜索的行爲不是什麼一個單元測試旨在用於 –
我還在考慮你可能會濫用單元測試來達到一個錯誤的目的。你能向我們解釋你的確切用例嗎? –