![](/img/trans.png)
[英]How to add a JUnit 4 test that doesn't extend from TestCase to a TestSuite?
[英]How to notate that the parameter value doesn't matter in a JUnit test?
我正在使用JUnit4,Mockito和Hamcrest進行一些TDD。 我當前的測試如下:
FeatureFilter featureFilter = FeatureFilter
.describeFeature()
.addFeatureRef("myNewFeature",
thatIsAvailable()
.atEndpoint("/resourceWithFeature"))
.andDisable();
assertThat(featureFilter.isDisabledFor("/resourceWithFeature", null, "myNewFeature"), is(true));
assertThat(featureFilter.isDisabledFor("/irrelevant", null, "myNewFeature"), is(false));
assertThat(featureFilter.isDisabledFor("/resourceWithFeature", null, "self"), is(false));
featureFilter.isDisabledFor
的第二個參數應該是用戶名( String
),我希望測試傳達的信息是在這種情況下用戶名無關緊要。 如果我處於測試雙打的情況下,則可以使用Matcher
例如any(String.class)
,但這不是這里的選擇。
作為開發人員,您將如何傳達此斷言的意圖?
有一個稱為JUnit Theories的功能。 @Test
和Theory
在測試上有不同的側重點:
適用於您的問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.