Configuration

uKnit is configured through uknit/resources/uknit.properites. The complete set of configurable properties, with default values, are defined in uknit-defaults.properties and users are need to know few of them and reconfigure them in uknit/uknit.properties.

Source Paths

The source class file is configured with following properties,

PropertyDescription
uknit.source.baseAbsolute path to the base of your project/module in IDE. Some examples are /orange/data/eclipse-workspace/scoopi-scraper, /home/m/IdeaProjects/playproject/workmodule. Note that in eclipse is path to your project and in IntelliJ it path to your module
uknit.source.dirDefaults to src/main/java. It relative path of source folder in your project/module.
uknit.source.packageThe qualified package name. Ex: org.apache.commons.dbcp2, java.time
uknit.source.clzThe name of the source class. Ex: Dog, Pet, Cluster

Destination

The generated test class is controlled with uknit.output.dir property which defaults to src/test/java. For following configurations

    uknit.source.base=/orange/data/eclipse-workspace/play
    uknit.source.dir=src/main/java
    uknit.source.package=org.example.foo
    uknit.source.class=Zoo
    
    uknit.output.dir=src/test/java

the test file ZooTest.java is created in /orange/data/eclipse-workspace/play/src/test/java/org/example/foo folder.

Overwrite The Test

By default uKnit doesn’t overwrite the test class if exists. To change this behaviour add following config in uknit/uknit.properties,

    uknit.output.file.overwrite=true

Configure paths for other Build Systems

The default paths follows Maven folder conventions. If you using IDE or any other build system then you have to adjust uknit.source.dir and uknit.output.dir accordingly. For example, the Eclipse Java Project places source files in src and tests in test folders and for such projects change/add these two configs in uknit/uknit.properties,

    uknit.source.dir=src        
    uknit.output.dir=test

Mock or Real

By default uKnit creates mock for all types excepts for types for which uknit.createInstance is defined. The uknit-defaults.properties defines createInstance config for many Collection types such as List, Map, Optional etc.,

    uknit.createInstance.List=new ArrayList<>()
    uknit.createInstance.Map=new HashMap<>()
    uknit.createInstance.Set=new HashSet<>()
    uknit.createInstance.Collection=new ArrayList<>()
    uknit.createInstance.String="${metasyntatic}"
    uknit.createInstance.Optional=Optional.empty()
    uknit.createInstance.Stream=Stream.of(STEPIN)

For above types uKnit doesn’t create mocks instead initializes them with values defined in config. For Example the a List is initialized as follows,

    List<LocalDate> dates = new ArrayList<>();

For any type if you want real instance then you can indicate so in uknit.properties. For example if you want real instance of Date then add a config in uknit.properties

    uknit.createInstance.Date=new Date();

Similarly for primitive types such as int, long etc., uKnit defines default values with config,

    uknit.createInstance.int=1
    uknit.createInstance.Integer=Integer.valueOf(1)

If you to change values of such items, change them by overriding the config in uknit.properties. To change int default value from 1 to 0 add the following,

    uknit.createInstance.int=0

Test Framework

uKnit can generate JUnit 4 or 5 tests and default is JUnit 5. To change it to 4, add the following in uknit.properties,

    uknit.profile.test.framework=junit4