GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — it's very difficult to unit test with non-publicly-constructable data types · Issue #2769 · googleapis/google-cloud-java

it's very difficult to unit test with non-publicly-constructable data types #2769

New issue
Copy link
New issue
Copy link
Closed
Closed
it's very difficult to unit test with non-publicly-constructable data types#2769
Copy link
Assignees
pongad
Labels
api: bigqueryIssues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Description

@pmkc
pmkc
opened on Jan 11, 2018
Issue body actions

I am writing a small wrapper around google-cloud-bigquery that is illustrated by

  public long getNumRows(BigQuery bq, String dataset, String table) {
    return bq.getTable(dataset, table)
        .<StandardTableDefinition>getDefinition()
        .getNumRows();
  }

When I go to unit test this method I have to mock out Table and StandardTableDefinition, because Table doesn't have a public builder and StandardTableDefinition's public builder does not have a public setNumRows.

This less usable than the underlying generated library where I can construct all the model objects directly. I have had this issue with other google-cloud-java components as well.

I understand the desire to minimize the public API for maintainability, but some kind of testing visibility for constructing ADTs would help a lot.

Activity

  1. vam-google
    added
    api: bigqueryIssues related to the BigQuery API.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jan 16, 2018
  2. vam-google commented on Jan 16, 2018

    @vam-google
    vam-google
    on Jan 16, 2018
    Contributor
    More actions

    I agree that being able to construct model objects has value and it would make the google-cloud-java clients more usable and testable.

    For your particular case, I believe the problem is in the overall approach chosen for the manual portion of google-cloud-java clients (BigQuery is one of them). It uses "thick" objects, which not only represent model, but also encapsulate the actual client. I.e. when you want to do something with your table you do somethign like:

    table.update(options)

    instead of:

    bigQueryService.updateTable(table, options)

    Since table object is much more than just a set of table properties/data, it is much harder (more dangerous) to expose its creation process, that is why it is hidden from surface.

    The new clients and already existing autogenerted ones (bigtable, dlp, all machine-learning clients (speech, video-intelligence and others) etc.) do not have this problem, they separate service and model objects, allowing you to instantiate them freely in your test code.

  3. vam-google
    added
    type: questionRequest for information or clarification. Not an issue.
    and removed
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Jan 16, 2018
  4. vam-google
    self-assigned this
    on Jan 16, 2018
  5. pmkc commented on Jan 16, 2018

    @pmkc
    pmkc
    on Jan 16, 2018
    Author
    More actions

    I'm not sure how dangerous adding @VisibleForTesting and public to Table.Builder's internal constructor, would be, but I understand it exposes implementation details of a thick object albeit one that just delegates to a BigQuery object.

    Making all fields of the pure datatype StandardTableDefinition.Builder settable on the other hand, would not in anyway expose implementation details.

  6. pongad
    closed this as completedin #2814on Jan 31, 2018
  7. pongad
    added a commit that references this issue on Jan 31, 2018

    bigquery: allow users to construct TableDefinition (#2814)

    This issue will close once commit 7ea0351 is merged into the 'main' branch.
    7ea0351
  8. theacodes
    unassigned
    vam-google
    on Sep 28, 2018
  9. JustinBeckwith
    assigned
    pongad
    on Feb 1, 2021
  10. chingor13
    added a commit that references this issue on Feb 20, 2026

    deps: update dependency com.google.http-client:google-http-client to …

    b0532b2
  11. suztomo
    added a commit that references this issue on Mar 9, 2026

    test(deps): update dependency com.google.cloud:google-cloud-storage t…

    792fb27
  12. chingor13
    added 4 commits that reference this issue on Mar 24, 2026

    deps: update opentelemetry-java monorepo to v1.38.0 (#2769)

    74a2451

    chore(main): release 2.40.1 (#2729)

    5697127

    build(deps): update dependency org.apache.maven.plugins:maven-failsaf…

    12c76ff

    chore: Update generation configuration at Thu Oct 10 02:23:40 UTC 2024 (

    81e96d3
  13. rahul2393
    added a commit that references this issue on May 21, 2026

    test: deflake stub test (googleapis#2769)

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

Metadata

Metadata

Assignees

  • @pongad
    pongad

Labels

api: bigqueryIssues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.