All Projects → jparams → to-string-verifier

jparams / to-string-verifier

Licence: MIT license
To String Verifier provides an easy and convenient way to test the toString method on your class.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to to-string-verifier

CI-Report-Converter
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).
Stars: ✭ 17 (-32%)
Mutual labels:  test, junit
Vscode Java Test
Run and debug Java test cases in Visual Studio Code.
Stars: ✭ 177 (+608%)
Mutual labels:  test, junit
flyway-junit5-extensions
Flyway JUnit 5 Extension to clean / migrate your database in tests.
Stars: ✭ 14 (-44%)
Mutual labels:  test, junit
Junitperf
⛵️Junit performance rely on junit5 and jdk8+.(java 性能测试框架)
Stars: ✭ 86 (+244%)
Mutual labels:  test, junit
Starwars-clean
Simple project with clean architecture
Stars: ✭ 34 (+36%)
Mutual labels:  test, junit
osgi-test
Testing support for OSGi. Includes JUnit 4 and JUnit 5 support and AssertJ support.
Stars: ✭ 22 (-12%)
Mutual labels:  test, junit
Expekt
BDD assertion library for Kotlin
Stars: ✭ 163 (+552%)
Mutual labels:  test, junit
action-junit-report
Reports junit test results as GitHub Pull Request Check
Stars: ✭ 103 (+312%)
Mutual labels:  test, junit
Junit Dataprovider
A TestNG like dataprovider runner for JUnit with many additional features
Stars: ✭ 226 (+804%)
Mutual labels:  test, junit
Androidunittest
Save time & clear your unit tests on Android !
Stars: ✭ 205 (+720%)
Mutual labels:  test, junit
Video Recorder Java
This library allows easily record video of your UI tests by just putting couple annotations.
Stars: ✭ 179 (+616%)
Mutual labels:  test, junit
scalatest-junit-runner
JUnit 5 runner for Scalatest
Stars: ✭ 30 (+20%)
Mutual labels:  test, junit
jpa-unit
JUnit extension to test javax.persistence entities
Stars: ✭ 28 (+12%)
Mutual labels:  test, junit
kit-assignment-tests
Test collection for KIT programming assignments (WS16/17)
Stars: ✭ 18 (-28%)
Mutual labels:  test, junit
tester-phpunit
tester runner for phpunit on atom editor
Stars: ✭ 34 (+36%)
Mutual labels:  tester
fixturez
Easily create and maintain test fixtures in the file system
Stars: ✭ 57 (+128%)
Mutual labels:  test
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (-12%)
Mutual labels:  test
cxx-tap
Test Anything Protocol (TAP) Producer for C++
Stars: ✭ 22 (-12%)
Mutual labels:  test
speed-cloudflare-cli
📈 Measure the speed and consistency of your internet connection using speed.cloudflare.com
Stars: ✭ 99 (+296%)
Mutual labels:  test
postchildren-desktop
👨‍👦‍👦 A E2E test visualization tool (get along with postman and postwoman)
Stars: ✭ 23 (-8%)
Mutual labels:  test

To String Verifier

Maven Central Build Status Javadocs

Getting Started

Get To String Verifier

Maven:

<dependency>
    <groupId>com.jparams</groupId>
    <artifactId>to-string-verifier</artifactId>
    <version>1.x.x</version>
    <scope>test</scope>
</dependency>

Gradle:

testImplementation 'com.jparams:to-string-verifier:1.x.x'

What is To String Verifier?

To String Verifier is the easiest, most convenient way to test the toString method on your class. toString methods are incredibly important for logging and debugging purposes, yet when it comes to testing, it is often forgotten or ignored. It is very easy to add a new field to your class and forget to update the toString method. Without tests in place, you won’t know something is missing until you are sitting looking through logs or debugging your application and by that time its already too late.

Write a Test

Writing a test is easy! In most cases you want to ensure that your toString method contains the class name and all the fields. Let's look at how we would write this test!

@Test
public void testToString()
{
    ToStringVerifier.forClass(User.class)
                    .withClassName(NameStyle.SIMPLE_NAME)
                    .verify();
}

Oh! A user object. I would not want to include the password in the toString, how do I exclude it from my test?

@Test
public void testToString()
{
    ToStringVerifier.forClass(Person.class)
                    .withClassName(NameStyle.SIMPLE_NAME)
                    .withIgnoredFields("password")
                    .withFailOnExcludedFields(true) // with this set true, if a developer accidently adds the password to the toString(), the unit test will fail
                    .verify();
}

To String Verifier is incredibly configurable, so take a look at the Java Docs for more options.

Package Scan

Some times you want to test a number of classes at once, or maybe all classes in a package. Well, we have you covered!

Testing multiple classes is as easy as: ToStringVerifier.forClasses(Person.class, Animal.class, Tree.class).verify()

To scan an entire package:

@Test
public void testToString()
{
    boolean scanRecursively = true; // when set to true, this will scan the given package and all subpackages.
    Predicate<Class<?>> predicate = (clazz) -> clazz.getName().endsWith("Model"); // optional parameter
    ToStringVerifier.forPackage("my.most.awesome.package", scanRecursively, predicate).verify();
}

Presets

To String Verifier also comes with a number of Vendor presets. These presets describe how different vendors style and format their toString output. Just tell us the Vendor preset to apply and begin testing!

ToStringVerifier.forClass(Person.class).withPreset(Presets.ECLIPSE).verify()

Here are all the Vendor presets available out of the box:

  • IntelliJ default style
  • Eclipse default style
  • Guava's MoreObjects toStringHelper.
  • Apache's ToStringBuilder. Supported ToStringStyles include:
    • JSON_STYLE
    • NO_CLASS_NAME_STYLE
    • DEFAULT_STYLE
    • MULTI_LINE_STYLE
    • SHORT_PREFIX_STYLE

Compatibility

This library is compatible with Java 8 and above.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].