[JAVA] I wanted to add @VisibleForTesting to the method

VisibleForTesting overview

Source code sample

@VisibleForTesting
protected void doSomething() {
  // ...
}

I never knew there was such an annotation. Well, I think it's easier to understand at a glance, "Why is it protected?" If it's a project that uses guava, it might be a good idea to try it.

By the way, package private has a narrower disclosure range than protected, so it may be safer to keep it package private. (I think I wrote it in the introduction to Junit practice ...)

Is it used quite a lot?

When I search on GitHub, it looks like an annotation that is used as it is. Some projects in Kotlin also have Visible For Testing.

Are there any other similar annotations?

com.google.common.annotations Visible For Testing is the only one that seems to be usable in business.

Background of writing this

I wrote Java for the first time in a few years, and I learned a lot, so I made a note of it. Maybe if you are a person who writes Android apps on a daily basis, is it a common sense level?

Recommended Posts

I wanted to add @VisibleForTesting to the method
The story I wanted to unzip
I was addicted to the roll method
4 Add println to the interpreter
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I want to add a delete function to the comment function
I want to expand the clickable part of the link_to method
I want to use the sanitize method other than View.
How to use the link_to method
Add Extended Attributes to the file
How to use the include? method
How to add the delete function
I tried to understand how the rails method "redirect_to" is defined
Method to add the number of years and get the end of the month
I want to add the disabled option to f.radio_button depending on the condition
I tried to understand how the rails method "link_to" is defined
I wanted to make JavaFX programming easier with the Spring Framework
[Java] I tried to make a maze by the digging method ♪
I tried to summarize the methods used
I just wanted to logrotate with log4j 2
[Ruby] From the basics to the inject method
[Rails] How to use the map method
[Java] How to use the toString () method
I tried to implement the Iterator pattern
I was addicted to the Spring-Batch test
I tried to summarize the Stream API
I went to the Java Women's Club # 1
I want to pass the argument of Annotation and the argument of the calling method to aspect
After all I wanted to preview the contents of mysql with Docker ...
I want to output the day of the week
Add empty data to the top of the list
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the session in Rails
What I tried when I wanted to get all the fields of a bean
Method to search
[Ruby] I want to do a method jump!
I want to var_dump the contents of the intent
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
When you want to use the method outside
Output of how to use the slice method
The code I used to connect Rails 3 to PostgreSQL 10
About the method
When I wanted to create a method for Premium Friday, it was already in the Java 8 standard API
How to use the replace () method (Java Silver)
Add classpath: to the path specified in spring.datasource.schema
I tried to set tomcat to run the Servlet.
I want to truncate after the decimal point
I wanted to gradle spring boot with multi-project
I wanted to start the AP server and debug with just the Maven command
[JDBC ③] I tried to input from the main method using placeholders and arguments.
Introducing what I made when I wanted to add a header and footer to RecyclerView
I want to get the value in Ruby
[Ruby basics] How to use the slice method
[Must-see for beginners] I changed the display of the posting time to Japanese time [l method]
I was addicted to the NoSuchMethodError in Cloud Endpoints
I tried what I wanted to try with Stream softly.
I want to call a method of another class
I tried to organize the cases used in programming
[Java] I want to calculate the difference from the date
I want to embed any TraceId in the log