Do not introduce unit test code of other modules in Maven multi-module projects.

Source: Internet
Author: User

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.