spring-bootgoogle-apigoogle-calendar-apijava-timejqwik

Are there tools like Jqwik for easily testing Google API's time class? (DateTime, EventDateTime...etc)


I was working on implementing test code for Google Calendar-related logic and came across a library called Fixture Monkey. To briefly explain, Fixture Monkey is a library that facilitates the creation of test objects when using JUnit.

Fixture Monkey provides a plugin for Jqwik, so generating arbitrary values for time classes supported by Java, such as LocalDateTime, was straightforward.

Generating Random LocalDateTime Values Using Fixture-monkey & Jqwik

default LocalDateTimeArbitrary localDateTimes() {
    LocalDateTime now = LocalDateTime.now();
    return DateTimes.dateTimes()
        .between(
            now.minusDays(365),
            now.plusDays(365)
        );
}

LocalDateTime generation TestCode

@Test
void localDateTimeRandomValueGenerationTest() {
    FixtureMonkey fixtureMonkey = new FixtureMonkeyBuilder()
        .plugin(new JqwikPlugin())
        .build();
    LocalDateTime localDateTime = fixtureMonkey.giveMeOne(LocalDateTime.class);
    System.out.println(localDateTime);
}

enter image description here

This class makes my life so much easier...

However, it seems that Jqwik does not support Google API's time classes such as EventDateTime. Therefore, Fixture-Monkey also does not provide random generation of values for Google API's time classes.😥

So I'm curious if there's a library like Jqwik that supports Google's time classes. And If there's a good library for testing Google Calendar API, please recommend one.

Have a nice day - kevin


Solution

  • It feels like it's been about a month since I started creating the library myself..!

    I've finally implemented a library that randomly generates Google time class (EventDateTime)

    I decided to write a comment to explain the simple usage.


    First, add the following dependency to your Gradle / Maven configuration.

    It's advisable to check the following link to verify if it's the latest version.

    // gradle
    
    implementation 'io.github.yonggoose:event-date-time-maker:0.7.5'
    
    //maven
    
    <dependency>
        <groupId>io.github.yonggoose</groupId>
        <artifactId>event-date-time-maker</artifactId>
        <version>0.7.5</version>
    </dependency>
    

    Second you can create an EventDateTime as follows

    EventDateTimeArbitrary eventDateTimeArbitrary = EventDateTimeArbitrary.builder()
        .setYear(2024)
        .setMonth(7)
        .setDay(7)
        .build();
    EventDateTime eventDateTime = eventDateTimeArbitrary.getEventDateTime();
    

    You can use the EventDateTimeArbitraryBuilder class to specify the year, month, and day, and you can also define a range using LocalDateTime.


    This project is open-source and licensed under the EPL-2.0 license.

    We plan to continue developing it for more features. Since it's still an early-stage library, there are many areas that need improvement.

    GitHub repository URL: https://github.com/IDMaker-io/MaKer

    If you'd like to contribute, please feel free to leave an issue!