我是SonarQube的新手,我需要使用它来分析Java Spring MVC代码。我添加了一个单元测试,但SonarQube分析未捕获添加的单元测试。以下是我要测试的代码行。
@Autowired
private InvoiceRepository repository;
public Invoice create(Invoice entity){
entity.setInvoiceId(UUID.randomUUID().toString());
return repository.insert(entity);
}
以下是我使用Junit编写的单元测试。
ObjectMapper mapper = new ObjectMapper();
Invoice obj = mapper.readValue(invoiceJson, Invoice.class);
InvoiceRepository dataServiceMock = mock(InvoiceRepository.class);
when(dataServiceMock.insert(invTest1)).thenReturn(new Invoice("ABC", "1", "INV-1", today, "FLTR-123", "Test Service Provider", null, "Cus Mane", "077777777", "06555555",
null, null, true, null, null, "BC", null, "43", true, null, null));
InvoiceService service = new InvoiceService();
Invoice invTemp = service.create(obj);
assertEquals(invTest1.getInvoiceId(), invTemp.getInvoiceId());
我也使用相关的软件包(pom.xml
和org.springframework.boot
)更新了org.jacoco
文件
SonarQube报告显示以下错误。
分析报告中的红线显示“测试未涵盖”。
如果有人可以帮助我解决此问题,那就太好了。
我使用以下命令通过命令行执行了分析
mvn sonar:sonar -Dsonar.host.url=http://localhost:9000