Skip to content

[Question] Unit Testing documentation #2113

Closed

Description

@MiguiTE

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?

Activity

  1. ashish10alex commented on Mar 17, 2026

    @ashish10alex
    Contributor

    @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.

    Image
  2. MiguiTE commented on Mar 19, 2026

    @MiguiTE
    Author

    Thanks @ashish10alex for the support and the quick release, I will try it out 😄

  3. MiguiTE commented on Mar 19, 2026

    @MiguiTE
    Author

    Hi @ashish10alex I was trying to test an action in one of my projects but couldn't do it

    Image

    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)

    What may I be missing?

  4. ashish10alex commented on Mar 19, 2026

    @ashish10alex
    Contributor

    Looks like a typo . You declared an action called c_out_title_local but the screenshot shows c_ou_title_local; missing a t

  5. MiguiTE commented on Mar 19, 2026

    @MiguiTE
    Author

    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.

    Again, sorry for the misunderstanding.

  6. ashish10alex commented on Mar 19, 2026

    @ashish10alex
    Contributor
    1. Can you share the config block of c_ou_title_local.sqlx
    2. Can you reporduce the same issue with this repo. Open 02_test.sqlx and compile.
    3. Also, I assume you are getting the same error when you compile in the terminal by running dataform compile
  7. MiguiTE commented on Mar 19, 2026

    @MiguiTE
    Author

    Yea sure:

    1. It's a pretty simple config block:
    config {
        type: "incremental",
        schema: "curated_cornerstone",
        uniqueKey: ["ou_id"]
    }
    
    1. 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?
    2. 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)
    
  8. ashish10alex commented on Mar 19, 2026

    @ashish10alex
    Contributor

    Thanks for providing the additional information. I managed to re-produce the issue.

    1. 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.
    2. 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.json see FAQ (3)
    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.
  9. MiguiTE commented on Mar 19, 2026

    @MiguiTE
    Author

    Thanks @ashish10alex for your help

    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"

    Image

    And finally, to support other config types, like incremental and operations should I open an issue at dataform repo?

  10. ashish10alex commented on Mar 19, 2026

    @ashish10alex
    Contributor

    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 : )

    new Error("Running tests on incremental datasets is not yet supported."),

  11. MiguiTE commented on Mar 19, 2026

    @MiguiTE
    Author

    Thanks for your help. I will assume that dry run stats reach a timeout.

    I will add that feature request 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions