Tag Archives: junit

[Solved] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

There is a mave aggregation project. The following error is reported when packaging through the maven command:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

The packaging command is as follows: clean package

Solution 1:
Click Toggle ‘Skip Tests’ mode in the maven panel in idea tools, and package it again and it works fine.
Solution 2:
Specify skipTests as true in the pom file to skip unit tests

	<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>

Solution 3:
Execute the command at the Terminal

mvn install -DskipTests

Solution 4:
Execute the command at the Terminal

mvn install -Dmaven.test.skip=true

Solution 5:
In the springboot project, spring-boot-maven-plugin plugin has been integrated with the maven-surefire-plugin plugin, will automatically run junit test, you need to add the following configuration in the pom

<properties>
 	<!-- skip the test -->
    <skipTests>true</skipTests>
</properties>

Among them, -Dmaven.test.skip=true and -DskipTests have the following roles

  • -DskipTests: does not execute the test cases, but compiles the test case classes to generate the corresponding class files under target/test-classes.
  • -Dmaven.test.skip=true: does not execute the test cases and does not compile the test case classes.

[Solved] shiro Error: org.apache.shiro.authc.UnknownAccountException:

Error reporting: error reporting during login

org.apache.shiro.authc.UnknownAccountException: Realm [org.apache.shiro.realm.SimpleAccountRealm@30cecdca] was unable to find account data for the submitted AuthenticationToken [org.apache.shiro.authc.UsernamePasswordToken - wmyskxz, rememberMe=false].

	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:184)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
	at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
	at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:274)
	at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:260)
	at com.example.demo.DemoApplicationTests.contextLoads(DemoApplicationTests.java:33)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

code:

package com.example.demo;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.SimpleAccountRealm;
import org.apache.shiro.subject.Subject;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;


@SpringBootTest
public class DemoApplicationTests {

    private SimpleAccountRealm simpleAccountRealm = new SimpleAccountRealm();

    @Before
    public void addUsr(){
        simpleAccountRealm.addAccount("wmyskxz","123456");
    }

    @Test
    void contextLoads() {
        DefaultSecurityManager defaultSecurityManager =  new DefaultSecurityManager();
        defaultSecurityManager.setRealm(simpleAccountRealm);

        SecurityUtils.setSecurityManager(defaultSecurityManager);
        Subject subject = SecurityUtils.getSubject();

        UsernamePasswordToken token = new UsernamePasswordToken("wmyskxz","123456");
        subject.login(token);

        System.out.println("isAuthenticated:"+subject.isAuthenticated());

        subject.logout();

        System.out.println("isAuthenticated:"+subject.isAuthenticated());

    }

}

The reason for the error is that Junit’s @Before did not register the account up, and the version of Junit, Spring Boot 2.2.9 default use is junit 5, in junit 5 @Before was @BeforeEach instead of @Before change @Before to @BeforeEach on it.

[Solved] o2o Error: addShopImg error:null / character to be escaped is missing

Operating system: Window10

1. During the JUnit test of ShopServiceTest, an error message is reported:addShopImg error:null as follows:

Solution: Modify the configuration information of PathUtil.java.

Check whether the two separators ofprivate static String separator=System. getProperty ("file. separator")are consistent and spelled correctly.

As long as the two separators are consistent and spelled correctly, there will be no null error message

2. The win10 system pops up:addShopImg error: character to be escaped is missing as follows:

Solution: Modify the configuration information of PathUtil.java.

Change all separator in replaceAll to Matcher quoteReplacement(separator)

Finally, the completely correct PathUtil.java source code is attached:

package com.imooc.o2o.util;

import java.util.regex.Matcher;

public class PathUtil {
	private static String separator = System.getProperty("file.separator");
	
	public static String getImgBasePath() {
		String os = System.getProperty("os.name");
		String basePath = "";
		if (os.toLowerCase().startsWith("win")) {
			basePath = "E:/Work/o2o/image";
		} else {
			basePath = "/home/Work/o2o/image";
		}
		basePath = basePath.replaceAll("/", Matcher.quoteReplacement(separator));
		return basePath;
	}
	
	public static String getShopImagePath(long shopId) {
		String imagePath = "upload/item/shop/" + shopId + "/";
		return imagePath.replaceAll("/", Matcher.quoteReplacement(separator));
	}
}

[Solved] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler – Unexpected error occurred in scheduled task.

When this error occurs, we should look at the following error message. Only this error is meaningless. What I see here is a java.lang.NoSuchMethodError. This error tells us that the method does not exist. The reason for this error may be that the package has not been introduced, or it may be a version conflict, resulting in the method not being found.

But the errors you may make are not like this, so you can search like this:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)

Today, adding Swagger2 to the project resulted in an error during project operation:

2019-05-06 15:05:02.348 [pool-2-thread-1] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V
	at org.openqa.selenium.remote.service.DriverService$Builder.usingPort(DriverService.java:278)
	at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:212)
	at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
	at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
	at com.unionpay.aiexamine.services.AutoLoginService.getCookie(AutoLoginService.java:23)
	at com.unionpay.aiexamine.config.SaticScheduleTask.getCookie(SaticScheduleTask.java:27)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
	at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Solution: add the following codes in the project maven

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.2.2</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>

How to Solve Mockito mockedStatic NotAMockException Error

Error Message:

org.mockito.exceptions.misusing.NotAMockException: Argument passed to Mockito.mockingDetails() should be a mock, but is an instance of class java.lang.Class!
    at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:52)
    at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:53)

 

Solution:
Delete @RunWith(MockitoJUnitRunner.class)
and add

    @Before
    public void before(){
        log.info("start--------{}",this.getClass().getName());
         MockitoAnnotations.openMocks(this);
    }

How to Solve Spring Boot Maven Build Error

Error 1:

[ERROR]Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project motherBuyBoot: There are test failures.
[ERROR] Please refer to D:\web\motherbuy\target\surefire-reports for the individual test results. [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.

Solution:

the pom.xml file has the wrong version of Junit, or for some other reason, the junit dependency is commented out and the compilation passes.

 

Error 2:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project motherBuyBoot: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Solution:

Method: Compile compile environment problems, that are not configured; see the screenshot below to solve, do not forget to update maven.

Junit4 unit test reports an error invalid project specified

Junit4 unit test reports an error invalid project specified.

During the unit test the day before yesterday, an invalid project specified error was reported. After checking, it was found that the problem was the project name. If there are illegal characters such as’ – ‘or space in the project name, an error invalid project specified will be reported when running

ed.

Error in idea unit test command line is too long

Question

Recently, I changed the computer and reconfigured the development environment. During unit testing, I found that the idea reported an error

Error running '*******Test.******' 
Command line is too ling. Shorten command line for ******* or also for JUnit default configuration.

Solution

Edit the workspace.xml tag under the project. Idea

<component name=“PropertiesComponent”>

Add next

<property name="dynamic.classpath" value="true" />

[Solved] Failed to resolve org.junit.platform:junit-platform-launcher:1.7.2

For springboot project, when using applicationtests to test, the following error will be prompted:

11:47 am  Error running ‘ShiroDemoApplicationTests.contextLoads’: Failed to resolve org.junit. platform:junit-platform-launcher :1.7.2

Reason: IntelliJ idea version and JUnit version do not match

solve:

1. Add the following dependencies to the pom.xml file of the project:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <scope>test</scope>
</dependency>

2. It is more troublesome to adjust the two versions to match. The first method is recommended.

Failed to retrieve platformtransactionmanager for @ transactional test: [defaulttest]

Foreword: This is JUnit test class. I hope that the data can be rolled back after the test, and the previous data will not be affected. But I have no problem in other tutorials. I report an error, and then I check a lot of data, but it is fruitless. Finally, I solve it by myself

Error message: java.lang.illegalstateexception: failed to retrieve platformtransactionmanager for @ transactional test

java.lang.IllegalStateException: Failed to retrieve PlatformTransactionManager for @Transactional test: [DefaultTestContext@6356695f testClass = SystemServiceTest, testInstance = com.****.****.oc.coresystem.service.SystemServiceTest@716f94c1, testMethod = update@SystemServiceTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4f18837a testClass = SystemServiceTest, locations = '{}', classes = '{class com.****.****.Application, class com.****.****.Application}', contextInitializerClasses = '[]', activeProfiles = '{dev}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@4d3167f4, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@87f383f, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@5891e32e, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@42607a4f], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]]
	at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:185) ~[spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:291) ~[spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) [spring-test-5.1.18.RELEASE.jar:5.1.18.RELEASE]
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.12.jar:4.12]
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) [junit-rt.jar:na]
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) [junit-rt.jar:na]
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) [junit-rt.jar:na]
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53) [junit-rt.jar:na]

The core reason for this problem in my project is that I have three different data sources in this large project, and JUnit does not know which data source transaction you want to roll back! It requires you to specify a platform transaction manager

Configuration of one of the primary data sources:

The test class then specifies the transactionmanager

Re run the test method, the problem is solved!

 
 

[Solved] Initialization error encountered by JUnit unit test: Method initialization error not found


The reasons may be as follows:
1. Methods with return values cannot be tested directly
2. Methods with parameters cannot be directly tested
3. Methods with access rights under public cannot be directly tested
Static static methods cannot be directly tested
5. Do not add an @test annotation to any of the first four conditions, or an initializationError will occur to any method that meets the @test condition


Only the methods of public void can be tested using @test

Point one: must be public, the following are not allowed
Point two: must be void, no return value, without any modification final, static, etc.

Many bloggers say it could be the lead pack problem:
in addition to introducing junit-4.12.jar, two dependent jars were introduced: hamcrest-core-1.3.rc2.jar, and hamcrest-library-1.3.rc2.jar
(Note: After personal testing, this is usually not the case.)