1.POM
<dependency> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.2</version> </dependency>
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.2</version> <configuration> <destFile>target/coverage-reports/jacoco-unit.exec</destFile> <dataFile>target/coverage-reports/jacoco-unit.exec</dataFile> <includes> <include>**/service/**</include> <!-- <include>**/controller/**</include>--> <include>**/utils/**</include> </includes> <!-- rules里面指定覆盖规则 --> <rules> <rule implementation="org.jacoco.maven.RuleConfiguration"> <element>BUNDLE</element> <limits> <!-- 指定方法覆盖到50% --> <limit implementation="org.jacoco.report.check.Limit"> <counter>METHOD</counter> <value>COVEREDRATIO</value> <minimum>0</minimum> </limit> <!-- 指定分支覆盖到50% --> <limit implementation="org.jacoco.report.check.Limit"> <counter>BRANCH</counter> <value>COVEREDRATIO</value> <minimum>0</minimum> </limit> <!-- 指定类覆盖到100%,不能遗失任何类 --> <limit implementation="org.jacoco.report.check.Limit"> <counter>CLASS</counter> <value>MISSEDCOUNT</value> <maximum>0</maximum> </limit> </limits> </rule> </rules> </configuration> <executions> <execution> <id>jacoco-initialize</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <!--这个check:对代码进行检测,控制项目构建成功还是失败--> <execution> <id>check</id> <goals> <goal>check</goal> </goals> </execution> <!--这个report:对代码进行检测,然后生成index.html在 target/site/index.html中可以查看检测的详细结果--> <execution> <id>jacoco-site</id> <phase>package</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin>
2.junit 示例
package cn.org.bjca.test; import cn.org.bjca.v2x.cmv.datastructs.secureddata.V2XSecData; import cn.org.bjca.v2x.enums.EndEntityCertType; import cn.org.bjca.v2x.helper.COERHelper; import cn.org.bjca.v2x.pca.Application; import cn.org.bjca.v2x.pca.entity.ApplicationStatisticsCert; import cn.org.bjca.v2x.pca.entity.IdentificationStatisticsCert; import cn.org.bjca.v2x.pca.entity.StatisticsCert; import cn.org.bjca.v2x.pca.service.ApplicationCertStatisticsService; import cn.org.bjca.v2x.pca.service.CertChainService; import cn.org.bjca.v2x.pca.service.IdentificationCertStaticsService; import cn.org.bjca.v2x.pca.service.NonPseudonymCertService; import cn.org.bjca.v2x.pca.service.PseudonymCertService; import cn.org.bjca.v2x.pca.service.PseudonymCertStatisticsService; import cn.org.bjca.v2x.pca.service.StatiscsApplicationCertService; import cn.org.bjca.v2x.pca.service.StatiscsIdentificationCertService; import cn.org.bjca.v2x.pca.service.StatisticsCertService; import cn.org.bjca.v2x.pca.utils.RestResponsePage; import cn.org.bjca.v2x.util.Base64Util; import com.github.pagehelper.PageInfo; import org.apache.xmlbeans.impl.xb.xsdschema.Public; import org.junit.Test; import org.junit.runner.RunWith; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.test.context.junit4.SpringRunner; /** * @author ****** * @date 2024/6/17 */ @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) @ComponentScan(basePackages = {"cn.org.bjca.v2x"}) @EntityScan(basePackages = {"cn.org.bjca.v2x"}) @EnableScheduling @MapperScan(basePackages = {"cn.org.bjca.v2x.*.mapper", "cn.org.bjca.v2x.web.common.mapper", "cn.org.bjca.v2x.component.mapper"}) public class YxlTest { @Autowired private PseudonymCertStatisticsService pseudonymCertStatisticsService; @Autowired private CertChainService certChainService; @Autowired private IdentificationCertStaticsService identificationCertStaticsService; @Autowired private ApplicationCertStatisticsService applicationCertStatisticsService; @Autowired private PseudonymCertService pseudonymCertService; @Autowired private NonPseudonymCertService nonPseudonymCertService; @Autowired private StatisticsCertService statisticsCertService; @Autowired private StatiscsApplicationCertService statiscsApplicationCertService; @Autowired private StatiscsIdentificationCertService statiscsIdentificationCertService; @Test public void testPc(){ RestResponsePage restResponsePage = new RestResponsePage(); int totalPages = restResponsePage.getTotalPages(); System.out.println(totalPages); certChainService.download("1"); } @Test public void testStatiscsPc(){ pseudonymCertStatisticsService.statPseudonymCerts(); identificationCertStaticsService.statIdentificationCerts(); applicationCertStatisticsService.statAppPseudonymCerts(); } @Test public void signedEncryptedCertApply(){ // V2XSecData v2XSecData = COERHelper.decode(V2XSecData.class, Base64Util.decode("A4OCAmkCAYOAYAEmfLQ6gAF8DgEBgiSkFcREigDZgnGEJOeVTemNceIqYv0YklKTSb8RSWVFYaYbrzYg21GC5DlOYLsCw8MRY0p7Nz1Ei3u94H+km9STQjDGP8P6Q5ZWcdSEX66HIItixyM7YejW6+n5RFgFygl4ZtGbm0hiIN37w4Gfv+MuYpIEaWKzOZuU0IEo7AEnWwKCBAGOrJtAG509+4TXGkF15uKRV0/uMg8IZzZWFegUZVHvIQGCIYNPoxkDS19lnKJoquJYlnlOPO/X0vDkaMEjWSs1XlMFZVCDAAAAAAEmfLQ6hACpgwEBgACcAQGAAW+AAICEIYIuHkeS1VcJU4S6Z2HyDD96gbhZnAvZIYL3PdmKYUh65IEBAYADAIMIBiZ6UIdsfPFXgQp3d3cucmEuY29tJGG0AAIl+nYFhgAMgwEBgACcAQGAAg4rgAOJAAEBAoCAAQ8AAg4gAAFvAAFwAAFxAAFyAAIOIQACDigAAg4iAAIOIwACDiQAAg4lAAIOJgACDicAAg4pAAIOKgEAgIABAQACDi0BAAGCIYJqcMwU2tODDm+A0Vnef/g2eDcT/QhXJWifa6z+E0gFToCEIYK2XjZSXFP/UT15lhBRmfFhi1Ji8eM8rWBt+yjaqIoz9YRA9jDq4BCBhagklJlVRyKN+/M9/Kcw9hNTeEEvq7Z9gDBZKY7DIia+Y5qubcwGsFsHuzlUrPcz5lnmsvMLCO9gBIRAIYK4yO1rV0t/L4GFywRGCNzc9xFWvYgxhFdglsN2BVqThlyDAksdUKUHZTFboJXE88IJNErobtPettkwMXnxcg==")); pseudonymCertService.genSignedAndEncryptedPseudonymCert(v2XSecData, "APP_0918B000A2C2469585BC9049E839E510"); } @Test public void createLinkageValueTables(){ pseudonymCertService.testSignedAndEncryptedPseudonymCert(); pseudonymCertService.createLinkageValueTables(); } @Test public void genBatchSignedAndEncryptedPseudonymCert(){ V2XSecData v2XSecData = COERHelper.decode(V2XSecData.class, Base64Util.decode("A4OCDCsCAYOCggrUAQpgASZ8qcWAAXwOAQGCJKQVxESKANmCcYS9QsGXjdGrDQJ4APEgeLyrvmf9OUjeZWDyjuhxNGfcyRGJgLXTye+hyMnE7e8ld6YCBOiEY/5u8PL47DcOQo8Pje3zRNt9A8QIKVsLToGNe5UuloPNeiO74JzlOXkKZLa7AeYYOGmtxcZmMXs+677DgSgOk4G7AO5gIaAOR8wbyeohEo2uFqAwIsFfY7kGpbm8JW+zxL9omkmgAYIhg3JQ/ub+g9GYhI3KiABQwgO3jlrlLRjkTzVOgfPMxBdFUIMAAAAAASZ8qcWEAKmDAQGAAJwBAYABb4AAgIQhgw4/sJZLRt4F5y4g8xDDI0PYXP99SQAZZOUJUZHQNFQOYAEmfKnFgAF8DgEBgiSkFcREigDZgnGE5r1CyQQeUsXyo4kN2rUgspfvmZEZWh78Is/7RVpEDfnClm/WNVx1l3KvZy9t0lkIxXF75Kxflwb5yzH5eInPwR3HcrOccPbNbYaGVcBKdgsaF0HgMC0YRmwa5whNyNNdw7dIp5kWB9uGRAFpsYLC1YEoUOqmlKT3mcqaUL8UG2u/YVmqSUn5YT939z905A0D4EB1pUX2agGF4QGCIYP8Vsm3eb5f407ht7zDxbBpyRr1kpTB6OpANtcLFdFh/lCDAAAAAAEmfKnFhACpgwEBgACcAQGAAW+AAICEIYJajCYMz2KfCsTemcykv+IgvE3pw3qLZnd8Io9S8RPhOWABJnypxYABfA4BAYIkpBXERIoA2YJxhEmThiRwb9l4e6Jjk6kEo4HdEk8CQFtYCxUYJckAHmbnafYcQUQi5O7/tyRyem7c+06eNqY1RFv/METhF5M9xzamEE8E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JsitY/9CaP5HPwaGYuy0OzfCvcW")); pseudonymCertService.genBatchSignedAndEncryptedPseudonymCert(v2XSecData, "APP_0918B000A2C2469585BC9049E839E510"); } //signApplicationCert @Test public void applyNonPseudonymCert(){ V2XSecData v2XSecData = COERHelper.decode(V2XSecData.class, Base64Util.decode("A4OCAboCAYOAAAEmfKyPQFCDAAAAAAEmfKyPhAAUgwEBgACcAQGAAW+AAICEQYQ1ACxa5smcpC7osinTem+ePLtqzqCqnT0dUsgWzuuDKwn8/8h4U0a4ytqfZeWdvLbXtD4Ijk6rMdfE8DWacBBQgQEBgAMAgwgGJnpQh2x88VeBCnd3dy5yYS5jb20kYbQAAiX6dgWGAAyDAQGAAJwBAYACDiuAA4kAAQECgIABDwACDiAAAW8AAXAAAXEAAXIAAg4hAAIOKAACDiIAAg4jAAIOJAACDiUAAg4mAAIOJwACDikAAg4qAQCAgAEBAAIOLQEAAYIhgmpwzBTa04MOb4DRWd5/+DZ4NxP9CFclaJ9rrP4TSAVOgIQhgrZeNlJcU/9RPXmWEFGZ8WGLUmLx4zytYG37KNqoijP1hED2MOrgEIGFqCSUmVVHIo378z38pzD2E1N4QS+rtn2AMFkpjsMiJr5jmq5tzAawWwe7OVSs9zPmWeay8wsI72AEhEBXPWjHfEiihgmgCGUo0QPV6PrQ48bGz/w6aVq/8rcHqo9QAI1PCVAC5L4XllUurG4ccEWMBMAkv7imYbjf9q7w")); nonPseudonymCertService.applyNonPseudonymCert(v2XSecData, EndEntityCertType.Application, "APP_0918B000A2C2469585BC9049E839E510"); V2XSecData v2XSecDataIc = COERHelper.decode(V2XSecData.class, Base64Util.decode("A4OCAboCAYOAAAEmfLB6QFCDAAAAAAEmfLB6hAAUgwEBgACcAQGAAW+AAICEQYQN7qzFrWx/g0T1VTZ3D83rTBg7ZpxDHi8u9hPBvboTgoTtOuWixuctnBySCHxaV5e42j8YJL/DsiqDM579RjbFgQEBgAMAgwgGJnpQh2x88VeBCnd3dy5yYS5jb20kYbQAAiX6dgWGAAyDAQGAAJwBAYACDiuAA4kAAQECgIABDwACDiAAAW8AAXAAAXEAAXIAAg4hAAIOKAACDiIAAg4jAAIOJAACDiUAAg4mAAIOJwACDikAAg4qAQCAgAEBAAIOLQEAAYIhgmpwzBTa04MOb4DRWd5/+DZ4NxP9CFclaJ9rrP4TSAVOgIQhgrZeNlJcU/9RPXmWEFGZ8WGLUmLx4zytYG37KNqoijP1hED2MOrgEIGFqCSUmVVHIo378z38pzD2E1N4QS+rtn2AMFkpjsMiJr5jmq5tzAawWwe7OVSs9zPmWeay8wsI72AEhECFj74Gqlmivkz2NnkwvGSmrvUcuFEnmtQBqdjqQXPYM8lp6qujd2su+leJhxNPTqaBUKphmvDCflanPHMefCbJ")); nonPseudonymCertService.applyNonPseudonymCert(v2XSecData, EndEntityCertType.Identification, "APP_0918B000A2C2469585BC9049E839E510"); } @Test public void queryCert(){ String startTime = "2024-05-01 00:00:00"; String endTime= "2024-06-17 00:00:00"; String raId= "APP_0918B000A2C2469585BC9049E839E510"; int pageNum= 1; int pageSize= 10; PageInfo<ApplicationStatisticsCert> applicationStatisticsCertPageInfo = statiscsApplicationCertService.listStatisticsAppCerts( startTime, endTime, raId, pageNum, pageSize); PageInfo<IdentificationStatisticsCert> identificationStatisticsCertPageInfo = statiscsIdentificationCertService.listStatisticsIdCerts( startTime, endTime, raId, pageNum, pageSize); PageInfo<StatisticsCert> statisticsCertPageInfo = statisticsCertService.listStatisticsPseudonymCerts( startTime, endTime, raId, pageNum, pageSize); } }
标签:cn,覆盖率,v2x,bjca,import,org,pca,jacoco,springboot From: https://www.cnblogs.com/wtxy/p/18254447