Cobertura de pruebas en Spring Boot con Jacoco y SonarCloud: configuración paso a paso

Hace poco me encontré con un problema bastante común al trabajar con proyectos en Spring Boot y SonarCloud: la cobertura de pruebas no se estaba reportando correctamente. Aunque las pruebas se ejecutaban sin errores, en SonarCloud la cobertura aparecía como si fuera 0%. ?Después de investigar...

? https://www.roastdev.com/post/....cobertura-de-pruebas

#news #tech #development

Favicon 
www.roastdev.com

Cobertura de pruebas en Spring Boot con Jacoco y SonarCloud: configuración paso a paso

Hace poco me encontré con un problema bastante común al trabajar con proyectos en Spring Boot y SonarCloud: la cobertura de pruebas no se estaba reportando correctamente. Aunque las pruebas se ejecutaban sin errores, en SonarCloud la cobertura aparecía como si fuera 0%. ?Después de investigar y probar diferentes configuraciones, logré que todo funcionara. Aquí te comparto lo que hice, por si te sirve.


1. Agregar la dependencia de mockito-inline
Uno de los problemas que tuve al usar Mockito fue con clases finales o métodos estáticos. Para solucionarlo, agregué esta dependencia en el archivo pom.xml:
⛶org.mockito
mockito-inline
5.2.0
test


2. Configurar Jacoco correctamente
El plugin de Jacoco debe estar bien configurado para generar el archivo jacoco.xml, que es el que SonarCloud usa para calcular la cobertura. Esta fue la configuración que usé en el pom.xml:
⛶org.jacoco
jacoco-maven-plugin
0.8.8


prepare-agent

prepare-agent


${project.build.directory}/jacoco.exec
surefireArgLine



report
test

report



XMLTambién fue necesario configurar el plugin de Surefire para que reciba los argumentos necesarios:
⛶org.apache.maven.plugins
maven-surefire-plugin

@{surefireArgLine} -Xshare:off


3. Configurar SonarCloud
Para que SonarCloud encuentre el archivo generado por Jacoco, es necesario agregar la siguiente ruta en su configuración:
⛶sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xmlPuedes hacer esto de dos formas:
En el archivo sonar-project.properties (si lo estás usando).
O directamente en la configuración del proyecto en la web de SonarCloud:

Ve a tu proyecto en SonarCloud.
Abre Administration General Settings JaCoCo.
En el campo "Path to XML report", coloca:

⛶target/site/jacoco/jacoco.xml


✅ Resultado
Después de aplicar estas configuraciones y ejecutar:
⛶mvn clean verifyEl reporte de cobertura fue generado correctamente y SonarCloud empezó a reconocer la cobertura real de las pruebas. ?


? Conclusión
No siempre es obvio cómo conectar bien Jacoco con SonarCloud en un proyecto Spring Boot, especialmente si estás empezando. Espero que este post te haya ayudado a evitar horas de prueba y error.

Similar Posts

Similar

Microsoft Copilot – Could It Transform How We Work

With AI firmly taking center stage following the launch of ChatGPT in late 2022, it’s clear that AI is rapidly becoming embedded in all aspects of our digital lives. Microsoft, having made significant investments in OpenAI and AI integration, continues to embed AI capabilities across its entire pr...

? https://www.roastdev.com/post/....microsoft-copilot-co

#news #tech #development

Favicon 
www.roastdev.com

Microsoft Copilot – Could It Transform How We Work

With AI firmly taking center stage following the launch of ChatGPT in late 2022, it’s clear that AI is rapidly becoming embedded in all aspects of our digital lives. Microsoft, having made significant investments in OpenAI and AI integration, continues to embed AI capabilities across its entire product ecosystem.


Microsoft’s AI Investment and Partnership with OpenAI
Microsoft's initial $10 billion investment in OpenAI at the start of 2023 marked a major commitment to AI innovation. This partnership was extended, positioning Microsoft as OpenAI's exclusive cloud provider and deeply integrating OpenAI's models into Azure AI services. This allows enterprises to use OpenAI’s advanced AI capabilities securely with their own private and sensitive data.


GitHub Copilot Evolution
Having acquired GitHub in 2018, Microsoft introduced GitHub Copilot in October 2021—an AI-powered coding assistant that leverages vast public code repositories to provide context-aware code suggestions directly inside VS Code and Visual Studio. This accelerated developers’ workflows by suggesting common code structures and automating routine coding tasks.In September 2023, Microsoft announced a major upgrade: GitHub Copilot Chat. This feature extends traditional code completion by offering a chat-based AI assistant that developers can interact with in real time. Features include:Real-time guidance tailored to coding challenges and best practices.
Code explanations and breakdowns of logic.
Security vulnerability identification and remediation suggestions.
Interactive debugging assistance.As of mid-2024, GitHub Copilot and Copilot Chat have expanded support beyond individuals to enterprise environments with more customization and context-awareness powered by enterprise data.


Microsoft 365 Copilot Goes Mainstream
Announced in early 2023 and rolling out progressively through 2023 and 2024, Microsoft 365 Copilot integrates OpenAI’s models directly into Microsoft 365 apps like Word, Excel, Outlook, Teams, and PowerPoint. Powered by organization-specific context and data (Microsoft Graph, SharePoint, OneDrive), it transforms productivity by:
Summarizing long Teams meetings with action points and follow-ups automatically.
Generating draft emails, reports, and presentations using natural language prompts.
Extracting insights from complex datasets and automating data analysis in Excel.
Dynamically creating and assigning tasks from meeting discussions.
Security and governance remain critical. Organizations must ensure data used by Copilot complies with privacy and regulatory standards and provide employee training for adoption. Microsoft continues to improve controls for data privacy and transparency in Copilot’s AI usage.


Windows Copilot Introduced for End Users
Windows Copilot rolled out with the Windows 11 2023 Update and is now generally available. It brings AI-driven assistance directly to users’ desktops, accessible via the taskbar or Win+C shortcuts. Its aim is to simplify everyday tasks with AI, without requiring users to understand the underlying technology. Highlights of the updated Windows Copilot include:
AI enhancements in built-in apps like Paint (background removal, AI-assisted creation), Photos (background blur, content-based photo search), and Snipping Tool (image text extraction and redaction).
Clipchamp integration for AI-assisted video editing with automatic scene creation and narration.
Notepad improvements including session restore and unsaved content recovery.
New Outlook for Windows integrating email accounts with AI-powered writing assistance.
Modernized File Explorer with intelligent search, collaboration insights, and new Gallery views for photos.
Accessibility improvements with advanced voice authoring tools and new Narrator voices.
Windows Backup feature streamlining PC migration with full app and settings transfer.
The Windows Copilot experience continues to evolve with monthly Windows updates, with Microsoft advancing AI-powered usability and task automation directly on the desktop.


Transforming Website Development with Microsoft Copilot
Microsoft Copilot is also reshaping the world of web development by providing AI-powered assistance that accelerates and enhances developers’ workflows. With tools like GitHub Copilot and Copilot Chat integrated into popular development environments such as Visual Studio Code, web developers can rapidly prototype, write, and debug their code with context-aware AI suggestions.Key impacts on web development include:
Faster Coding: Copilot suggests full code snippets, components, and boilerplate code in real time, significantly reducing manual typing and speeding up feature implementation.
Improved Code Quality: The AI helps catch potential bugs, security vulnerabilities, and performance issues early by recommending best practices and writing test cases.
Simplified Learning Curve: Junior developers benefit from explanations of complex code and learn how to use new frameworks or APIs quickly with natural language queries answered directly within the IDE.
Enhanced Collaboration: Copilot can generate documentation, code comments, and technical specifications, facilitating clearer communication across distributed development teams.
Customization and Context Awareness: Enterprises can fine-tune Copilot with their internal coding standards and repositories, ensuring AI suggestions align with company requirements and branding.
Overall, Microsoft Copilot is transforming web development from a labor-intensive process to a more creative, efficient, and collaborative discipline — empowering developers to focus on innovation rather than repetitive coding tasks.



Looking Ahead: The AI Era Has Truly Begun
While concerns around job impacts and data privacy remain, these AI tools aim to augment human skill rather than replace it, automating repetitive or tedious tasks and allowing us to focus on higher-value, creative, or strategic work.The first generation of AI-powered Copilots is just the beginning. As the models improve and new capabilities emerge, we can expect AI to become an indispensable part of how we work, create, and communicate in the years ahead.It’s an exciting time to witness and participate in this transformation. Let’s embrace these new possibilities and see where they take us next!
Similar

Such a refreshing angle on why so many campaigns underperform.


Sign in to view linked content
...

? https://www.roastdev.com/post/....such-a-refreshing-an

#news #tech #development

Favicon 
www.roastdev.com

Such a refreshing angle on why so many campaigns underperform.

Sign in to view linked content
Similar

Exploring Generative AI with the Gemini API in Vertex AI

I recently completed the "Explore Generative AI with the Gemini API in Vertex AI" course as part of the Google GenAI Exchange Program, where I explored the potential of Generative AI using Gemini and Vertex AI.This course focused on leveraging the Gemini API within Vertex AI, a powerful suite for bu...

? https://www.roastdev.com/post/....exploring-generative

#news #tech #development

Favicon 
www.roastdev.com

Exploring Generative AI with the Gemini API in Vertex AI

I recently completed the "Explore Generative AI with the Gemini API in Vertex AI" course as part of the Google GenAI Exchange Program, where I explored the potential of Generative AI using Gemini and Vertex AI.This course focused on leveraging the Gemini API within Vertex AI, a powerful suite for building, deploying, and scaling machine learning models. I learned how to integrate Gemini’s cutting-edge language model into custom applications, enabling a wide range of AI-driven functionalities from natural language generation to personalized recommendations.The course also emphasized fine-tuning and customizing Gemini for specific use cases, enhancing the accuracy and relevance of the generated content. By using Vertex AI, I was able to deploy AI solutions quickly and efficiently, while gaining valuable experience in working with APIs to create impactful, real-world applications.