instancio/instancio
Sobre
Uma biblioteca que cria objetos totalmente preenchidos para seus testes unitários.
Ferramentas de desenvolvimentoCrescimento medido de estrelas
- em 24 h
- +2
- em 7 dias
- +2
- em 15 dias
- +2
- em 1 mês
- +4
Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.
README.md
Original
User Guide | Javadocs | Quickstart project
What is it?
Instancio is a Java library that automatically creates and populates objects for your unit tests.
Instead of manually setting up test data:
Person person = new Person();
person.setFirstName("first-name");
person.setAge(22);
person.setAddress(address);
//...
You can simply do the following:
Person person = Instancio.create(Person.class);
This one-liner returns a fully-populated person, including nested objects and collections. The object is populated with random data that can be reproduced in case of test failure.
What else can Instancio do?
Create collections and streams:
List<Person> persons = Instancio.ofList(Person.class).size(10).create();
Stream<Person> stream = Instancio.stream(Person.class).limit(5);
Customise generated values:
Person person = Instancio.of(Person.class)
.generate(field(Person::getDateOfBirth), gen -> gen.temporal().localDate().past())
.generate(field(Phone::getNumber), gen -> gen.text().pattern("#d#d#d-#d#d-#d#d"))
.set(field(Person::getLastName), "Simpson")
.create();
Reuse object templates (Models):
Model<Person> simpsons = Instancio.of(Person.class)
.set(field(Person::getLastName), "Simpson")
.toModel();
Person homer = Instancio.of(simpsons)
.set(field(Person::getFirstName), "Homer")
.create();
Inject arguments with JUnit (video tutorial):
@ExtendWith(InstancioExtension.class)
class ExampleTest {
@Test
void example(@Given Person person, @Given String name) {
//...
}
@RepeatedTest(100)
void repeated(@Given UUID id) {
// runs 100 times with different generated inputs
}
}
Installation 
Add the dependency using the latest version shown in the Maven Central badge above. See the documentation for other modules, including the BOM.
Maven
<dependency>
<groupId>org.instancio</groupId>
<artifactId>instancio-junit</artifactId>
<version>LATEST_VERSION</version>
<scope>test</scope>
</dependency>
Gradle
testImplementation("org.instancio:instancio-junit:LATEST_VERSION")
Sponsors
Find Instancio useful, or use it in a commercial product? Please consider supporting its maintenance, or ask your company to, via GitHub Sponsors or Open Collective.
Thanks to JetBrains for supporting Instancio with their open source licenses.
Backers
For Enterprise
Available as part of the Tidelift Subscription.
The maintainers of Instancio and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
Feedback
Feedback and bug reports are greatly appreciated!
- Please submit an issue for bug reports and feature requests.
- For general feedback or questions, please create a post in the Discussions.
Explore projetos relacionados
Carregando…
