package io.hosuaby.inject.resources.examples.junit5.tests;
import com.adelean.inject.resources.junit.jupiter.GivenTextResource;
import com.adelean.inject.resources.junit.jupiter.TestWithResources;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@TestWithResources // <-- Add @TestWithResources extension
public class MyTestClass {
// Read content of resource alice.txt into String field
@GivenTextResource("/io/hosuaby/alice.txt")
String fieldWithText;
@Test
void testWithTextFromResource() {
// We can use content of resource file in our test
assertThat(fieldWithText)
.isNotNull()
.isNotEmpty()
.isNotBlank()
.contains("Alice");
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter