how often does the letter "i" occur in:
q: what are the drawbacks of modeling (unit) test fixtures in json instead of using objectfactories? when writing java tests for an application, be they unit tests or testing a broader scope, the java community tends to model fixtures in terms of object factories that produce fixtures of a defined state.
eg:
public class testfixturegeneratora{
    static public a modelastate1(){
        a a = new a();
        a.setfoo(1);
        a.setbar("bar");
    }
    static public a modelastate2(){
        a a = new a();
        a.setfoo(2);
        a.setbar("baz");
    }
}

whereas, coming from a bdd or agile methodologies perspective, it would seem more sensible to encode fixtures in terms of their applied scenario and feature or test.
eg:
//file: src/test/resources/fixtures/scenarioa/interaction1/a.json
{
    foo: 1,
    bar: "bar"
}

//file: src/test/resources/fixtures/scenarioa/interaction2/a.json
{
    foo: 2,
    bar: "baz"
}

//file: src/test/resources/fixtures/scenarioa/interaction2/ids.json
[42, 101, 1337]

and then have your test execute in the scope provided by scenarioa interactionx.
i have seen this kind of thing in agile driven teams that model from business requirement to code (ie: they maintain a full bdd stack), none of them java shops) and once in a relatively big industry application. but trying to look up literature on the practice was fruitless. there does seem to be one implementation at corballis' github repository providing annotation based test infrastructure, similar to the one described above but other than that the web seems devoid of work on this subject.
given the succinctness of json and the probably better formalization/integration aspects of the json based fixture mechanic, how come it didn't get discussed until now? are there any apparent drawbacks i'm missing?
note:
this is taken from personal experience in a multitude of projects, mostly in java, highly diversified (some where millions sloc, others have insane performance requirements, etc).

a: i've written tests that were json supported before. here were the drawbacks:


*

*json is not compiler-checked. this means if you add a field to your models, you won't know your test json is broken until you try to run the tests and they all fail.

*json is more difficult to produce than code. in my case our models were quite complex, so i would start by copying another json file and tweaking it.

*json can't contain comments. you can't document the important features of the json file that make it appropriate for the scenario.

*ide integrations for json are not as advanced as those for code. for example i can jump to definitions and attributes in code, but i can't do that for json. there is a separation between the code and the json files that may make it difficult understand at a glance which json file is being used in a test. some knowledge of a naming convention (in your example) would be necessary, and i would have to navigate to the file in my ide or os, and parse it visually and with text search.



it would seem more sensible to encode fixtures in terms of their applied scenario and feature or test.

what does this have to do with using json or not? you can produce an object tailored to your feature under test in code. that would be my preference. it is a trade-off because the code will likely be quite long.
you can treat long construction code by creating builders for complex models. so instead of
a a = new a();
a.setfoo(2);
a.setbar("baz");

you could write
a a = new abuilder().foo(2).bar("baz").build();

or create a factory
a a = new afactory(2, "baz").create();


a: if an integrationtest (or json based test) fails you know that something is wrong but you cannot be shure which component caused the problem. it could be the json parser/mapper, the businesslogic or any other module involved in the test.
if a unittest (in isolation with factorymethods) fails it is likely that the single module under test caused the problem.
for me the info that "something is wrong" is good enough so i prefer using deserialised testdata (from json, csv or xml)
this question is an issue between unittesting  versus integrationtesting where both have their pros and cons.

user
The total number of "i"s in that passage is 245.
assistant