考虑这个测试
@Test
public void testGetClientIdTwiceReturnsDifferentClientIdsForSameUser() {
final UniqueIdGenerator uniqueIdGenerator = new UniqueIdGenerator("testClientId");
final String email = "uniqueEmail@gmail.com";
final String userExternalId = UUID.randomUUID().toString();
assertNotEquals(uniqueIdGenerator.getClientId(email, userExternalId), uniqueIdGenerator.getClientId(email, userExternalId));
}
我希望使用相同的数据运行100
次,只需确保每次生成的ID都不同。
我在Spring看到有@Repeat
注释,我们是否有类似JUnit的东西?
答案 0 :(得分:2)
你想运行它100次,但是你不想独立地运行每次迭代 ,因为你想要将每次迭代的输出相互比较(以确保它们都是独特的,所以参数化不是最好的方法。
我只会循环100次:
Set<String> set = new HashSet<Set>();
for (int i = 0; i < 100; i++) {
assertTrue(set.add(uniqueIdGenerator.getClientId(email, userExternalId)));
仅供参考,如果要添加的元素已经在集合中,则set.add()
返回false。