[ 
https://issues.apache.org/jira/browse/FLINK-26845?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17519511#comment-17519511
 ] 

Salva edited comment on FLINK-26845 at 4/8/22 10:47 AM:
--------------------------------------------------------

I played with Stateful Functions a bit using the Golang SDK and I could not 
find anything  related to mocking. So, this is how I tested my functions 
[~trohrmann] :

```go
package internalimport 
"github.com/apache/flink-statefun/statefun-sdk-go/v3/pkg/statefun"// 
StatefunContext wraps the statefun context for mocking// Generate mocks by 
running "go generate ./mocks/internal/..."//go:generate mockery --name 
StatefunContext --output "./../../mocks"type StatefunContext interface

{ statefun.Context}

//go:generate mockery --name StatefunStorage --output "./../../mocks"type 
StatefunStorage interface

{ statefun.AddressScopedStorage}

```

Then you can use the generated mocks just normally...I don't think there is 
much room for imagination here, what are your thoughts?


was (Author: JIRAUSER287051):
I played with Stateful Functions a bit using the Golang SDK and I could not 
find anything  related to mocking. So, this is how I tested my functions 
[~trohrmann] :

```go
package internalimport 
"github.com/apache/flink-statefun/statefun-sdk-go/v3/pkg/statefun"// 
StatefunContext wraps the statefun context for mocking// Generate mocks by 
running "go generate ./mocks/internal/..."//go:generate mockery --name 
StatefunContext --output "./../../mocks"type StatefunContext interface

{ statefun.Context}

//go:generate mockery --name StatefunStorage --output "./../../mocks"type 
StatefunStorage interface

{ statefun.AddressScopedStorage}

```

Then you can use the generated mocks just normally...I don't think there is 
much room for imagination here, what are your thoughts?

> Document testing guidelines
> ---------------------------
>
>                 Key: FLINK-26845
>                 URL: https://issues.apache.org/jira/browse/FLINK-26845
>             Project: Flink
>          Issue Type: Improvement
>          Components: Stateful Functions
>            Reporter: Salva
>            Priority: Minor
>
> As of now, there seems to be not much guidance on how to approach testing. 
> Although it's true [~sjwiesman] that 
> {quote}Unlike other flink apis, the sdk doesn’t pull in the runtime so 
> testing should really look like any other code. There isn’t much statefun 
> specific.
> {quote}
> I think that at the very least testing should be mentioned as part of the 
> docs, even if it is only to stress the above fact. Indeed, as reported by 
> [~trohrmann], there seems that there are already some test utilities in place 
> but they are not well-documented, plus some potential ideas on how to improve 
> on that front
> {quote}Testing tools is definitely one area where we want to improve 
> significantly. Also the documentation for how to do things needs to be 
> updated. There are some testing utils that you can already use today: 
> [https://github.com/apache/flink-statefun/blob/master/statefun-sdk-java/src/main/java/org/apache/flink/statefun/sdk/java/testing/TestContext.java…|https://t.co/WGjyMA510b].
>  However, it is not well documented.
> {quote}
> Once the overall guidelines are in place for different testing strategies, 
> tests could be added to the examples in the 
> {_}[playground|https://github.com/apache/flink-statefun-playground]{_}.
> {_}Note{_}: Issue originally reported in Twitter: 
> [https://twitter.com/salvalcantara/status/1505834101026267136?s=20&t=Go2IHP6iP4ZmIyVLmIeD3g]



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to