在junit中,每個測試都應該獨立運行。對於更復雜的程序,你通常運行設置方法。但是我需要像每個參數之前運行的setup方法。每個參數的Junit參數化測試
可以說我有這樣的測試用例:
setup()
contructor()
test1()
test2()
test3()
teardown()
從執行我的JUnit的參數化測試,這將落得像這樣用2個PARAMS:
setUpBeforeClass
contrcutor called
test1 running
contrcutor called
test2 running
contrcutor called
test3 running
contrcutor called
test1 running
contrcutor called
test2 running
contrcutor called
test3 running
tearDownAfterClass
我需要的是一種叫做在每個參數之前。所以結果會是這樣的(改變方法與「()」):
setUpBeforeClass
contrcutor called
setupParam()
test1 running
contrcutor called
test2 running
contrcutor called
test3 running
contrcutor called
tearDownParam()
setupParam()
test1 running
contrcutor called
test2 running
contrcutor called
test3 running
tearDownParam()
tearDownAfterClass
我知道JUnit測試應該是原子,但每PARAM設置,過程是非常昂貴的。有沒有辦法實現這種執行順序?
在此先感謝!
更新:
@Before作爲第一個答案只會導致通話每測試之前。 例子:
setUpBeforeClass
contrcutor called
before
test1 running
contrcutor called
before
test2 running
contrcutor called
before
test3 running
contrcutor called
before
test1 running
contrcutor called
before
test2 running
contrcutor called
before
test3 running
tearDownAfterClass
@Before只會導致在每次測試之前執行before()方法。我想在每個參數前執行一次。 – whereismydipp
我更新了問題。你可以看到結果和我的意思。 – whereismydipp