Source: http://blog.csdn.net/chaijunkun/article/details/35796335. For more information, see. I will sort out relevant blog posts from time to time and improve the relevant content. Therefore, we strongly recommend that you view this article in the original source.
In the past two days, I have been sorting out some old code and upgrading the original chaos to Maven management. This also inevitably splits large projects into several modules (correct a pronunciation here, not "cat drop", yes['M memory? D? Ul]Many people, including me, read the error. However, in order to save time during the test, a basetest is created in src/test/Java in the Basic module referenced by each module,
package net.csdn.blog.chaijunkun.util;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations="classpath:applicationContext*.xml")public abstract class BaseTest {@Testpublic abstract void doTest();}
All unit test classes in other modules are inherited from basetest. This eliminates the trouble of writing the preceding annotations. However, noclassdeffounderror: net/csdn/blog/chaijunkun/util/basetest appeared during the test. The strange thing is that the src/main/Java code that introduces public units can be loaded normally.
Later, I figured out that the maven unit test model was built on the idea of "independence, the purpose is to verify the availability and correctness of its modules without interference from other environments. Therefore, code at the test level cannot be referenced by other modules.
After the unit test code of other modules is removed from the src/test/Java-level reference, the project is successfully built.