Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I test my external dependencies? #252

Open
gdamoreira opened this issue Feb 19, 2021 · 0 comments
Open

How should I test my external dependencies? #252

gdamoreira opened this issue Feb 19, 2021 · 0 comments

Comments

@gdamoreira
Copy link

gdamoreira commented Feb 19, 2021

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";
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant