Run Parameterized Tests — Weak Accesses vs Constructor

Rafael Ruiz Muñoz
Jan 12, 2018 · 1 min read

Today I started adding some parameterized tests to my app, and I realised that there are not much documentation for Kotlin.

Anyway, the difficulty shouldn’t be really high as it’s much as it was in Java, except for Weak Accesses. I will try to make this as a manual to achieve a good test suite.

I want to talk about the difference between the Constructor access and the Weak access.

Imagine we want to do Unit tests in a RectangleModel like:

Parameterized tests Constructor Based:

Parameterized tests using Weak Accesses:

Note that you will have to use @JvmField annotation otherwise Java will see that parameter private if you’re coding in Kotlin!

Which one would you use, and why?
Comments are well received!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store