Skip to content

Instantly share code, notes, and snippets.

@dg3feiko
Last active December 7, 2016 09:35
Show Gist options
  • Save dg3feiko/a085f4027c715b866377b0c98a1a0f36 to your computer and use it in GitHub Desktop.
Save dg3feiko/a085f4027c715b866377b0c98a1a0f36 to your computer and use it in GitHub Desktop.

Java

  • Reflection
  • Change modifier to protected and put tests into same place

Go

/github.com/example/mypackage.go
                   /mypackage_internal_test.go                   

Rust

fn private_function() {
}

#[test]
fn test_private_function() {
    private_function()
}

Javascript

No private/public, do whatever you want

Elixir

- have faith in your unit tests: when they test the public api of your module they also test the private api
- write more tests for your public api, have you covered all scenarios ?
- extract your private api to its own module, most functions should become public and testable

Python

  • subclassing the class to expose access
  • tricks with runtime introspective features

C#

  • Reflection or other access modifier tricks similar to Java

C++

  • Friend access modifer
  • macro
  • subclassing
  • refactor to separate file and expose interfaces

Ruby

  • Send (dynamic dispatch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment