approvals/ApprovalTests.Java
소개
ApprovalTest verification library for Java
개발 도구What you can do
- HashMaps & Collections
- Getting Legacy Code under tests Want to see more? Check out Better Testing with Approvals
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalContents
- What can it be used for?
- Documentation
- Getting started
- How to get it
- Podcasts
- Examples
- Approved File Artifacts
- More Info
- LICENSE
- Developer notes
ApprovalTests.Java
Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid unit testing.
It is compatible with JUnit 3, 4 & 5 and TestNG.
Works on JDK 1.8+ (tested on 1.8, 17, 21, 24, 25, 26).
What can it be used for?
Approval Tests can be used for verifying objects that require more than a simple assert. They also come prepackaged with utilities for some common java scenarios including
HashMaps & Collections
Long Strings
Log Files
JPanels
Xml
Html
Json
Getting Legacy Code under tests
Want to see more? Check out Better Testing with Approvals
Documentation
Missing Documentation?
If there is documentation you wish existed, please add a page request to this issue.
Getting started
New Projects
The best way to get started is download and open one of the starter projects:
These are standard projects and can be imported into any editor or IDE.
They also all have CI with Github actions.
Docs
You might also want to check out the Getting Started Overview
Learning
A great way to learn Approval Tests if you are new to it is to try out the Koans.
How to get it
It's on Maven Central, search for 'approvaltests'.
Maven
If you're using Maven, add this to your pom file:
<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<version>32.2.0</version>
<scope>test</scope>
</dependency>
Gradle
dependencies {
testImplementation("com.approvaltests:approvaltests:32.2.0")
}
or download the jars from maven central repository
Minimizer
Just what you use, Nothing you don't. ApprovalTests.Java.Minimizer scans your project for the ApprovalTests calls you actually make, and builds a custom ApprovalTests jar that contains only that code. For the StarterProject the jar shrinks from 948 KB to 252 KB, and it no longer needs Jackson, XStream, Quartz and other dependencies it doesn't use.
Video Tutorials
You can watch a bunch of short videos on getting started and using ApprovalTests in Java at youtube.
Note: There are a lot of videos about ApprovalTests in .Net They are equally useful for understanding the concepts despite being in a different programming language.
Podcasts
If you prefer auditory learning, you might enjoy the following podcast (Note: Some of these talk about the .net side)
Examples
ApprovalTests eats it own dogfood, so the best examples are in the source code itself.
None the less, Here's a quick look
public class SampleArrayTest
{
@Test
public void testList()
{
String[] names = {"Llewellyn", "James", "Dan", "Jason", "Katrina"};
Arrays.sort(names);
Approvals.verifyAll("", names);
}
}
Will Produce a File SampleArrayTest.testList.received.txt
[0] = Dan
[1] = James
[2] = Jason
[3] = Katrina
[4] = Llewellyn
Simply rename this to SampleTest.testList.approved.txt and the test will now pass.
Approved File Artifacts
The *.approved.* files must be checked into source your source control.
This can be an issue with git as it will change the line endings.
The suggested fix is to add
*.approved.* binary to your .gitattributes
More Info
No Checked Exceptions Philosophy
Approval Tests follows the no checked exceptions" philosophy. That is, our API only throws runtime exceptions.
LICENSE
Questions?
twitter: @LlewellynFalco or #ApprovalTests
Developer notes
The suggested way to contribute to ApprovalTests is to pair with Llewellyn
However, if you are set on forking please read these notes
관련 프로젝트 살펴보기
불러오는 중…