Skip to content
Back

Testing functions best practice?

  • 0
  • Flutter
  • Functions
  • Cloud
whataboutno13
27 Sep, 2023, 13:52

I am trying to test my dart functions locally before I deploy them to the cloud. Sadly with the new update to v1.4 I can no longer set the req.variables with the needed variables. In my head there are these options for testing functions:

  • Testing locally and setting the Platform.environment variables (How?)
  • Creating a real execution on cloud (Cant do that bc of the dart / dart_appwrite version)
  • Integreation test from flutter App

Since my tests worked locally I would really like to just modify them slightly to work again. Has someone an Idea how to do that?

And in general, what is expected to be the best practice for testing the functions?

Thanks for your help in advance! <:appwriteheart2:1073243188954935387>

TL;DR
The user is looking for best practices for testing functions locally before deploying them to the cloud using Appwrite. They have tried setting environment variables but it is not an optimal solution. The user suggests two workarounds: 1. Use --define or --dart-define when running the functions and access via String.fromEnvironment. 2. Create a separate runtime request and add an environment variable to distinguish between local tests and Appwrite. The user also mentions that testing directly in Appwrite is problematic because of the build process and compatibility issues with different versions of Dart. Another user suggests testing in Appwrite to ensure incremental functionality and avoid issues that may
Drake
27 Sep, 2023, 21:15

I highly suggest testing in Appwrite. one way is to use a local instance of Appwrite. The reason why I would test in Appwrite and build incrementally is to make sure things work incrementally. There could be something different between your simulated local test and Appwrite where it works locally, but not in Appwrite and if you have hundreds of lines of code, it may be difficult to figure out what part is causing the problem

whataboutno13
28 Sep, 2023, 09:03

Ok my problem with testing directly in appwrite is splitted. Firstly I am unpatient and do not want to wait for the build process of the function 😉 Secondly and more important, for developing the functions for cloud I have installed dart 2.17 which is not compatible with dart_appwrite higher than 8.0.1. With this setup I am not able to call createExecution with the newly published options like body or headers. So I would have to install another dart version just to test the function?

freppsa
28 Sep, 2023, 12:26

Hi @whataboutno13

I encountered a similar scenario, where I prefer testing my functions locally for more straightforward debugging prior to running in Appwrite.

Unfortunately altering the Platform.environment during runtime isn’t possible. There is a request for this feature in the Dart language repository, but I couldn't find the issue at the moment.

I discovered two potential workarounds.

  1. Use --define // --dart-define when running the functions and access via String.fromEnvironment.

2.Create your own RuntimeRequest, add an environment variable, and then insert logic in your code to distinguish between locally test and appwrite.. Example check if the variable exists in Platform.environment. If absent, presume it's a test and utilize the added environment variable instead.

I did go for the second alternative at the moment. I do find option 1 more cleaner, and will probably go for that in the future.

I hope this helps you, let me know if you have any questions.

whataboutno13
28 Sep, 2023, 14:03

Hi @freppsa, thank you for your response! My solution for local testing right now is actually setting my windows environment variables to the required ones from my functions. Not ideal but this way I do not have to distinguish between local test and appwrite cloud. Still not an optimal solution.

I mean local testing makes debugging and stuff so much easier, thats why I am confused why its so focused on testing only in appwrite. Feels like going directly going into integration testing and leaving unit testing behind. Or am I wrong about this? 🤔

freppsa
29 Sep, 2023, 06:50

That’s an third option! Yes I completely agree - i do unit testing and integration testing locally and only after that I deploy functions to an test instance.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more