FlexTradeUKLtd / jfixture

JFixture is an open source library based on the popular .NET library, AutoFixture
MIT License
105 stars 22 forks source link

Documentation on how to add "implementors" #41

Open philipwhiuk opened 6 years ago

philipwhiuk commented 6 years ago

Say you get an error like this:

JFixture was unable to create an instance of play.api.libs.json.JsValue
Most likely because it has no public constructor, is an abstract or non-public type or has no static factory methods.
If this isn't the case it's likely that all constructors and factory methods on the type have thrown an exception.
To view any thrown exceptions just add the Tracing Customisation to the JFixture instance, e.g. fixture.customise(new TracingCustomisation(System.out));

        List[package.mypackage.ThingIWant] --> 
        package.mypackage.ThingIWant --> 
        package.mypackage.ThingIWant --> 
        public package.mypackage.ThingIWant(long,java.lang.String,java.lang.String,java.time.LocalDateTime,boolean,java.lang.String,flextrade.wham.messages.Schedule,java.lang.String,java.lang.String,play.api.libs.json.JsValue) --> 
        play.api.libs.json.JsValue --> 
        play.api.libs.json.JsValue

What you really want to do is to customise the fixture with something to implement JsValue.

It would be nice to expand the README with how to do this.

TWiStErRob commented 6 years ago

Take a look at fixture.customise().*(): there are multiple options there that would help to resolve the issue. In your case it's likely a lazyInstance with a reusable SpecimenSupplier, or a useSubType(JsValue.class, JsObject.class).