You could let your @Setup method initialize your serviceAPI if (and only if) it's null. For your tests, pre-initialize it with a Fake, and otherwise the real thing will get used.
On Sat, May 25, 2024 at 1:27 PM Ritwik Dutta via dev <dev@beam.apache.org> wrote: > > Hi Hu, > > Thank you, > I am testing the serviceAPI call in separate unit tests already. Let me > rephrase (serviceAPI should be renamed to serviceLayer, it doesn't > necessarily have to be a restful API with an http endpoint) > The question is how, do we create Fakes for items with difficult constructors. > > At least provide examples, or more explanation in Apache dcoumentation. > > Feel free to reply directly in stackoverflow, so other community members can > reply > > Thanks! > > -Ritwik Dutta > 734-262-4285 > > On Saturday, May 25, 2024 at 07:12:23 AM PDT, XQ Hu <x...@google.com> wrote: > > > I am not sure which part you want to test. If the processData part should be > tested, you could refactor the code without use any Beam specific code and > test the processing data logic. > > From your example, it seems that you are calling some APIs, we recently added > a new Web API IO: https://beam.apache.org/documentation/io/built-in/webapis/, > which provides a way to test. > > On Wed, May 22, 2024 at 5:06 PM Ritwik Dutta via dev <dev@beam.apache.org> > wrote: > > any response yet? No one has answers? I left a stackoverflow bounty on the > question > > Using external methods is pretty important > > On Sunday, May 12, 2024 at 11:52:25 AM PDT, Ritwik Dutta <rdutt...@yahoo.com> > wrote: > > > Hi, > I wrote the following question here. > It would be really helpful also, if you can also update your documentation on > Using Test Fakes in different Situations. It was very light documentation. > Please provide more explanation and examples. > https://beam.apache.org/documentation/io/testing/#:~:text=non%2DBeam%20client.-,Use%20fakes,-Instead%20of%20using > > > Question: Java Apache Beam, mock external Clients initialized in @Setup > method of DoFn with Constructors variables > https://stackoverflow.com/questions/78468953/java-apache-beam-mock-external-clients-initialized-in-setup-method-of-dofn-wit > > Thanks, > > -Ritwik Dutta > 734-262-4285