I was addicted to rewriting to @SpringApplicationConfiguration-> @SpringBootTest

Spring 5.0.x and Spring Boot 2.0.x have been released, but this time I will write what I was addicted to when refactoring the code implemented using the old Spring version.

Thing you want to do

Since @SpringApplicationConfiguration has been deprecated since Spring 1.4, I would like to replace it with @SpringBootTest, which is provided as an alternative annotation. The environment is Spring Boot (1.4.8), PowerMock (1.6.5)

Where I was addicted

Looking at the Official blog, it seems that you can just rewrite the annotation, but the test When I try to run it, I get a ClassNotFoundException.

TestSample.java


@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@PrepareForTest(Hoge.class)
public class TestSample
{
   @Before
   public void setUp() throws Exception {
       PowerMockito.mockStatic(Hoge.class);
   }
 ...
}
java.lang.ClassNotFoundException: com.example.PowermockClassLoadTest$Config$$EnhancerBySpringCGLIB$$e0ecd163

Cause

When using PowerMock v1.6.5 or earlier together, it seems that a ClassNotFoundException occurs due to a bug in PowerMock. Reference issue 1, Reference issue 2

Correspondence

Since the bug has been fixed in 1.6.6, let's not only rewrite the Spring annotation but also specify the PowerMock version to 1.6.6 or later.

pom.xml


<dependencies>
  <dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-module-junit4</artifactId>
    <version>1.6.6</version>
    <scope>test</scope>
  </dependency>
</dependencies>

reference

Recommended Posts

I was addicted to rewriting to @SpringApplicationConfiguration-> @SpringBootTest
I was addicted to starting sbt
I was addicted to the roll method
I was addicted to the Spring-Batch test
I was addicted to using RXTX on Sierra
I was addicted to installing Ruby/Tk on MacOS
I was addicted to doing onActivityResult () with DialogFragment
I was addicted to the NoSuchMethodError in Cloud Endpoints
I was addicted to the record of the associated model
What I was addicted to when introducing the JNI library
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
I was addicted to setting default_url_options with Rails devise introduction
I was addicted to looping the Update statement on MyBatis
A story I was addicted to in Rails validation settings
I was addicted to the setting of laradock + VSCode + xdebug
What I was addicted to with the Redmine REST API
I was addicted to using Java's Stream API in Scala
The story I was addicted to when setting up STS
Android memo-I was addicted to Permission
[Circle CI] A story I was addicted to at Start Building
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
What I was addicted to when implementing google authentication with rails
About the matter that I was addicted to how to use hashmap
I was addicted to the API version min23 setting of registerTorchCallback
Memorandum: What I was addicted to when I hit the accounting freee API
[Rails] I was addicted to the nginx settings when using Action Cable.
A story I was addicted to when testing the API using MockMVC
My.cnf configuration problem that I was addicted to when I was touching MySQL 8.0 like 5.7
I was addicted to a simple test of Jedis (Java-> Redis library)
Problems I was addicted to when building the digdag environment with docker
Recorded because I was addicted to the standard input of the Scanner class
I was a little addicted to running old Ruby environment and old Rails
I was addicted to scrollview because I couldn't tap the variable size UIView
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was a little addicted to ssh connection from mac to linux (ubuntu)
I was addicted to unit testing with the buffer operator in RxJava
I was addicted to not being able to connect to AWS-S3 from the Docker container
I was a little addicted to the S3 Checksum comparison, so I made a note.
SpringSecurity I was addicted to trying to log in with a hashed password (solved)
What I was addicted to when developing a Spring Boot application with VS Code
A memo that I was addicted to when making batch processing with Spring Boot
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
What I was addicted to when trying to properly openAPI/Swagger documentation with Rails + Grape + Grape Swagger
A story I was addicted to when getting a key that was automatically tried on MyBatis
GetXxxx of ResultSet was addicted to primitive type (Java)
A story I was addicted to before building a Ruby and Rails environment using Ubuntu (20.04.1 LTS)
A story I was addicted to with implicit type conversion of ActiveRecord during unit testing
I was addicted to WSl when trying to build an android application development environment with Vue.js
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
What I was addicted to when updating the PHP version of the development environment (Docker) from 7.2.11 to 7.4.x
[Rails] How to solve ActiveSupport :: MessageVerifier :: InvalidSignature that I was addicted to when introducing twitter login [ActiveStorage]