Skip to content

How should I test my external dependencies? #252

Description

@gdamoreira

Hi team,

I'm using FnProject now and I'm using external dependencies to access external resources and I'm trying to mock to test the function without dependencies in it. How should I mock my external resource?

public class FunctionTest {

    @Rule
    public final FnTestingRule testing = FnTestingRule.createDefault();

    @Test
    public void shouldReturnGreeting() {
        testing.givenEvent().withBody("{\"data\":123}").enqueue();
        testing.thenRun(Function.class, "handleRequest");

        FnResult result = testing.getOnlyResult();
        assertEquals("OK", result.getBodyAsString());
    }

}

public class Function {
    public ExternalResource getExternalResource() {
        return new ExternalResource(); // how to mock this?
    }
    public String handleRequest(String inputData) {
        var externalResource = getExternalResource();
        externalResource.doSomething();
        return "OK";
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions