Skip to content

vijayparashar12/tostringverifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ToStringVerifier

if you are frustrated by every time your class coverage fails because of toString() method implementation.

class Foo{
    private final String bar;
    private final String baz;
    Foo(String bar,String baz){
        this.bar = bar;
        this.baz = baz;
    }
    
    @Override
    public String toString(){
        return MoreObjects.toStringHelper(this)
        .add("bar",bar);
    }
}

class FooTest {
    @org.junit.Test
    public void testConsiderAllFields(){
        Foo foo = new Foo(bar);
        tostringverifier.ToStringVerifier.forClass(Foo.class).with(foo).verify();
    }
    @org.junit.Test
    public void testExceptSpecificFiled(){
        Foo foo = new Foo(bar);
        tostringverifier.ToStringVerifier.forClass(Foo.class).with(foo).exceptFields("baz").verify();
    } 
    
    @org.junit.Test
    public void testWithSpecificFiled(){
        Foo foo = new Foo(bar);
        tostringverifier.ToStringVerifier.forClass(Foo.class).with(foo).withfields("bar").verify();
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages