Skip to content

Instantly share code, notes, and snippets.

View CsvFileSourceParameterizedTest.java
class CsvFileSourceParameterizedTest {
/**
* CSV File Source
*/
@ParameterizedTest
@CsvFileSource(resources = "test.csv")
void csvFileSource(String first, int second) {
assertNotNull(first);
assertNotEquals(0, second);
}
View CsvSourceParameterizedTest.java
class CsvSourceParameterizedTest {
/**
* CSV Source
*/
@ParameterizedTest
@CsvSource({"foo, bar", "foo, 'bar, hoge'", "foo, ''", "foo, "})
void csvSource(String first, String second) {
System.out.println(String.format("first: %s, second: %s", first, second));
}
}
View EnumSourceParameterizedTest.java
class ParameterizedTestDemo {
@ParameterizedTest
@EnumSource(Gender.class)
void enumSourceAll(Gender gender) {
assertTrue(Arrays.asList(Gender.values()).contains(gender));
}
@ParameterizedTest
@EnumSource(value = Gender.class, names = {"MAN", "WOMAN"})
void enumSourceInclude(Gender gender) {
View Gender.java
public enum Gender {
MAN, WOMAN
}
View Person.java
public class Person {
private String firstName;
private String lastName;
private int age;
private Gender gender;
View StringsValueParameterizedTestDemo.java
class StringsValueParameterizedTestDemo {
private Person person1;
private Person person2;
@BeforeEach
void beforeEach() {
person1 = new Person("Ryosuke", "Uchitate", 27, Gender.MAN);
person2 = new Person("Taro", "Uchitate", 20, Gender.MAN);
}
View PageWrapperTest.java
class PageWrapperTest {
private PageWrapper pageWrapper;
@Mock
private Page page;
private Method initPaginationMethod;
private int totalPages;
@b1a9id
b1a9id / PageWrapper.java
Last active Jan 16, 2018
ページネーション作成メソッド
View PageWrapper.java
private List<Integer> initPagination(int paginationSize) {
if (getTotalPages() < paginationSize) {
return IntStream.range(0, paginationSize)
.boxed()
.collect(Collectors.toList());
}
// ページネーションサイズが偶数かどうか
boolean isEvenSize = paginationSize % 2 == 0;
int currentPageNumber = this.page.getNumber();
View RepeatedTestDemo#BeforeEach
About to execute repetition 1 of 3 for RepeatedTestDemo#noArgs
About to execute repetition 2 of 3 for RepeatedTestDemo#noArgs
About to execute repetition 3 of 3 for RepeatedTestDemo#noArgs
About to execute repetition 1 of 1 for RepeatedTestDemo#customDisplayNameLongPattern
About to execute repetition 1 of 3 for RepeatedTestDemo#totalRepetitionsInfo
About to execute repetition 2 of 3 for RepeatedTestDemo#totalRepetitionsInfo
About to execute repetition 3 of 3 for RepeatedTestDemo#totalRepetitionsInfo
About to execute repetition 1 of 3 for RepeatedTestDemo#customDisplayName
About to execute repetition 2 of 3 for RepeatedTestDemo#customDisplayName
About to execute repetition 3 of 3 for RepeatedTestDemo#customDisplayName
View RepeatedTestDemo.java
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class RepeatedTestDemo {
@BeforeEach
void beforeEach(TestInfo testInfo, RepetitionInfo repetitionInfo) {
// 現在の回数
int currentRepetition = repetitionInfo.getCurrentRepetition();