You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any documentation about how to configure unit test to actions?
I don't see any documentation in Google Cloud Dataform Docs on how to implement views, however, I can see people configuring test #1824.
How can I define unit tests, input cases and expected output of an action? How can I run tests? Is it possible to run tests in Google Cloud Dataform or with the Dataform VSCode Extension, or at least locally with Dataform CLI and a terminal?
Hi @ashish10alex I was trying to test an action in one of my projects but couldn't do it
I am declaring a table OU_TITLE_LOCAL that is used in an action c_out_title_local to solve incremental changes base on a upload date column. As you can see in the test file I am declaring the dataset as c_out_title_local, which is the action that I want to test.
I am declaring a input to replace BQ OU_TITLE_LOCAL table. But I am getting a compile error:
Error compiling Dataform:Dataset c_ou_title_local could not be found. at definitions\test\ou_title_local_test.sqlx
Run `dataform compile` to see more details.
My environment:
@dataform/cli: 3.0.48 (node global package)
@dataform/core: 3.0.38 (declared in workflow_settings.yaml)
Sorry, it's not a typo in the code but in the message. I write it wrong here, however, as you can see in the code screenshot, the middle file, which is the test file, is correctly written as c_ou_title_local, the same name as the action c_ou_title_local.sqlx.
I cannot reproduce it. If I open the repo in codespaces (option 1) it request me to load credentiales, if I login with my account i will not work as I do not have access to the example GCP project. I have also cloned the repo to my local computer and when I run dataform compile it works just fine. If I run 'dataform test' it throws an error Missing credentials JSON file; not found at path 'C:\Users\Miguel\Documents\workspace\labs\football_dataform\.df-credentials.json'. What should this file have to make it work?
Same error but with the stack
Compilation errors:
definitions\tests\ou_title_local_test.sqlx: Error: Dataset c_ou_title_local could not be found.
at d.compile (C:\Users\Miguel\AppData\Local\Temp\tmp-42792-TEhDbu7S6BMg\node_modules\@dataform\core\bundle.js:15:50640)
at C:\Users\Miguel\AppData\Local\Temp\tmp-42792-TEhDbu7S6BMg\node_modules\@dataform\core\bundle.js:15:82936
at Array.forEach (<anonymous>)
at t.Session.compileGraphChunk (C:\Users\Miguel\AppData\Local\Temp\tmp-42792-TEhDbu7S6BMg\node_modules\@dataform\core\bundle.js:15:82909)
at t.Session.compile (C:\Users\Miguel\AppData\Local\Temp\tmp-42792-TEhDbu7S6BMg\node_modules\@dataform\core\bundle.js:15:81343)
at t.main (C:\Users\Miguel\AppData\Local\Temp\tmp-42792-TEhDbu7S6BMg\node_modules\@dataform\core\bundle.js:15:72984)
at C:\Users\Miguel\AppData\Local\Temp\tmp-42792-TEhDbu7S6BMg\index.js:1:96
at VM2 Wrapper.apply (C:\Users\Miguel\AppData\Local\nvm\v22.16.0\node_modules\@dataform\cli\node_modules\vm2\lib\bridge.js:493:11)
at NodeVM.run (C:\Users\Miguel\AppData\Local\nvm\v22.16.0\node_modules\@dataform\cli\node_modules\vm2\lib\nodevm.js:497:23)
at compile (C:\Users\Miguel\AppData\Local\nvm\v22.16.0\node_modules\@dataform\cli\worker_bundle.js:30216:23)
Thanks for providing the additional information. I managed to re-produce the issue.
Looks like dataform cli does not support actions that are of type incremental in tests. I got the same error as you. Try an action of type table in your test, it should work.
Yes, the issues you see are expected when running the tests in that repo as they are pointed to my gcp project. I wanted you to just compile the project and see if you get any compilation errors for the tests in the project. dataform compile. Regarding .df-credentials.jsonsee FAQ (3)
This affirms that this is not an issue with the extension. However expected behaviour with the current version of dataform cli. Not sure if this is purposefully by design though.
I've made a couple of changes to set the action as a table type, and now I don't get any errors. I could execute the test after initialising credentials with dataform init-creds.
There's one thing that isn't working as expected; I'm not sure why, and it is not a big deal. It keeps loading "Performing dry run"
And finally, to support other config types, like incremental and operations should I open an issue at dataform repo?
Thanks for confirming that it works with type of the action set to "table" .
keeps loading "Performing dry run"
It should display you the dry run stats similar to BigQuery. If it keeps loading I would, first try to reload VS Code window and recompile. Check if you dont have any network issues, sometimes BigQuery dry run api can take long or not respond until timeout is reached if you are behind a proxy.
to support other config types, like incremental and operations should I open an issue at dataform repo
This is the exact line which confirms that excluding incremental type from test is intentional. However, we do not get this error due to a bug in the error checking logic. But feel free to create a feature request anyways. If its feasible someone will add it : )
Activity
ashish10alex commentedon Mar 17, 2026
@MiguiTE , I have added support for tests in the VS Code extension v1.4.0.
You can see some example tests both using both .sqlx, .js files here.
MiguiTE commentedon Mar 19, 2026
Thanks @ashish10alex for the support and the quick release, I will try it out 😄
MiguiTE commentedon Mar 19, 2026
Hi @ashish10alex I was trying to test an action in one of my projects but couldn't do it
I am declaring a table
OU_TITLE_LOCALthat is used in an actionc_out_title_localto solve incremental changes base on a upload date column. As you can see in the test file I am declaring the dataset asc_out_title_local, which is the action that I want to test.I am declaring a
inputto replace BQOU_TITLE_LOCALtable. But I am getting a compile error:My environment:
What may I be missing?
ashish10alex commentedon Mar 19, 2026
Looks like a typo . You declared an action called
c_out_title_localbut the screenshot showsc_ou_title_local; missing atMiguiTE commentedon Mar 19, 2026
Sorry, it's not a typo in the code but in the message. I write it wrong here, however, as you can see in the code screenshot, the middle file, which is the test file, is correctly written as
c_ou_title_local, the same name as the actionc_ou_title_local.sqlx.Again, sorry for the misunderstanding.
ashish10alex commentedon Mar 19, 2026
c_ou_title_local.sqlxdataform compileMiguiTE commentedon Mar 19, 2026
Yea sure:
dataform compileit works just fine. If I run 'dataform test' it throws an errorMissing credentials JSON file; not found at path 'C:\Users\Miguel\Documents\workspace\labs\football_dataform\.df-credentials.json'. What should this file have to make it work?ashish10alex commentedon Mar 19, 2026
Thanks for providing the additional information. I managed to re-produce the issue.
incrementalin tests. I got the same error as you. Try an action of typetablein your test, it should work.dataform compile. Regarding.df-credentials.jsonsee FAQ (3)MiguiTE commentedon Mar 19, 2026
Thanks @ashish10alex for your help
I've made a couple of changes to set the action as a
tabletype, and now I don't get any errors. I could execute the test after initialising credentials withdataform init-creds.There's one thing that isn't working as expected; I'm not sure why, and it is not a big deal. It keeps loading "Performing dry run"
And finally, to support other config types, like
incrementalandoperationsshould I open an issue at dataform repo?ashish10alex commentedon Mar 19, 2026
Thanks for confirming that it works with type of the action set to "table" .
It should display you the dry run stats similar to BigQuery. If it keeps loading I would, first try to reload VS Code window and recompile. Check if you dont have any network issues, sometimes BigQuery dry run api can take long or not respond until timeout is reached if you are behind a proxy.
This is the exact line which confirms that excluding incremental type from test is intentional. However, we do not get this error due to a bug in the error checking logic. But feel free to create a feature request anyways. If its feasible someone will add it : )
dataform/core/actions/test.ts
Line 185 in 412d523
MiguiTE commentedon Mar 19, 2026
Thanks for your help. I will assume that dry run stats reach a timeout.
I will add that feature request 😄