Array
(
)

How to use code coverage in your Mendix team

Friday June 21, 2024
Markus Travaille, Rolf Bolt

Introduction

In our previous blog we explained how you can apply code coverage for Mendix apps. With the introduction of MTA 2.7 we will support the measurement of code coverage and we will allow you to specify coverage goals for specific parts (modules, types of microflows, …).

This blog is not about the technical part of code coverage, but deals with the organizational part and how to apply an effective code coverage strategy in your Mendix teams.

Start with a product risk analysis

A product risk analysis helps you to identify, assess, and prioritize the potential risks that may affect the quality, functionality, or usability of your Mendix app. A product risk  analysis is a qualitative analysis that can help you to identify which parts of your Mendix app should benefit from automated tests. However, it cannot measure the actual coverage of the automated tests.

Code coverage on the other hand provides a quantitative measure of which parts of the code have been tested and, more importantly, which not. Code coverage and product risk analysis can complement each other by providing different perspectives and insights on the quality and testing process of your Mendix app.

What are coverage goals in MTA?

Coverage goals in MTA help you to measure coverage for specific parts of your application. E.g. the coverage for

  • a specific module
  • a specific group of microflows (all validation microflows)
  • the latest added microflows

Watch the video for a more detailed explanation

Use a product risk analysis to prioritize code coverage goals

One possible way to use product risk analysis to prioritize code coverage goals is to identify the critical and high-risk features or components of the Mendix app, and then aim for a higher level of code coverage for those parts by setting specific coverage goals. For example, if the Mendix app handles important business data, data quality related code should have a high code coverage goal, while less important code can have a lower goal. This way, the automated tests can be directed towards the most important aspects of the quality of the Mendix app and reduce the chances of missing defects or errors in the high-risk areas.

Who should set code coverage goals

Code coverage goals are not fixed or universal, but rather depend on various factors, such as the type, size, scope, and complexity of your Mendix app, the resources and time available for testing, the quality standards and expectations of your stakeholders, and the trade-offs between coverage and size of your tests. Therefore, code coverage goals should be set by the people who are most familiar with and responsible for these factors, such as the Mendix team, testers, product owners, or clients involved in the project. Ideally, code coverage goals should be set collaboratively and iteratively, with input and feedback from all relevant parties, and with clear communication and documentation of the rationale and criteria for the goals.

Code coverage goals should also be reviewed and updated regularly, as Mendix apps can evolve fast and new requirements or challenges emerge. By setting code coverage goals in a realistic, flexible, and transparent manner, you can ensure that they reflect the needs and expectations of your software project, and that they guide and motivate you to achieve high-quality code.

Keep your coverage goals up to date

Once you have defined the important areas for which you want to set code coverage goals you need to define a strategy on how to keep the goals up to date. There is no definitive answer to how often you need to update code coverage goals, as it may depend on various factors such as the size, complexity, and scope of your Mendix app, the frequency and type of your releases, the expectations and requirements of your customers and stakeholders, and the standards and best practices of your industry or domain. However, some general guidelines that can help you decide when to update your code coverage goals are:

  • Update goals for each release: Update your code coverage goals whenever you introduce a major change or feature to your Mendix app, such as adding new functionality, modifying existing functionality, fixing bugs, or refactoring the code. This can help you ensure that your automated tests cover the new or changed code adequately, and that your Mendix app maintains its quality and performance after the change.
  • Update goals when the trend is breaking: Update your code coverage goals whenever you observe a significant deviation or variation in your code coverage trend, such as a sudden increase or decrease in code coverage, or a fluctuation or inconsistency in code coverage over time. This can help you identify and address any issues or challenges in your Mendix app development or testing process, such as insufficient or outdated test cases, code duplication or complexity, technical debt, or regression errors.
  • Update goals by updating your product risk analysis: Update your code coverage goals whenever you receive feedback or input from your customers or stakeholders, such as user reviews, complaints, suggestions, or feature requests. This can help you align your code coverage goals with the needs and expectations of your target audience, and enhance the usability and satisfaction of your Mendix app. User feedback is actually helping you to improve your product risk analysis.
  • Update your goals periodically:  Update your code coverage goals periodically, such as every month, quarter, or year, depending on the duration and cycle of your Mendix app. This can help you review and evaluate your code coverage progress and achievements, and adjust your code coverage goals accordingly to reflect the current state and direction of your Mendix app.
  • Do not update goals too often: Updating your code coverage goals regularly can help you keep your quality and performance of your Mendix app at an optimal level, and deliver software that meets or exceeds the expectations and requirements of your customers and stakeholders. However, updating your code coverage goals too frequently or arbitrarily can also have negative effects, such as creating unrealistic or unattainable expectations, wasting time and resources, or demotivating your Mendix team. Therefore, you should update your code coverage goals carefully and strategically, based on the evidence and data from your code coverage reports and analyses, and the feedback and input from your customers and stakeholders.

Monitor coverage trends to identify missing test cases

A trend in code coverage can help you monitor the progress and quality of the development and testautomation of your Mendix app over time. A positive trend in code coverage means that your automated tests are covering more of the source code, which can imply that your Mendix app is becoming more reliable, robust, and secure. A negative trend in code coverage means that your automated tests are covering less of the Mendix model, which can imply that your Mendix app is becoming more complex, unstable, or vulnerable. By analyzing the trend in code coverage, you can identify the causes and effects of the changes in your Mendix app, and take appropriate actions to improve quality and performance of your Mendix app. For example, you can add or modify test cases to increase the code coverage, or refactor or redesign the code to reduce complexity and improve maintainability. A trend in code coverage can also help you set realistic and achievable goals for releases of your Mendix app, and communicate the quality and status of your Mendix app to your stakeholders.

Use code coverage results in your release criteria

Code coverage can be used in a release strategy for your Mendix app  to determine the readiness and quality of the Mendix app for deployment. Code coverage measures how much of the source code is executed by the automated tests, and can indicate the effectiveness and completeness of the testing process. By setting a minimum code coverage threshold for each release, the Mendix team can ensure that the Mendix app meets a certain standard of quality and functionality before it is delivered to the customers. Additionally, code coverage can help identify the areas of the code that need more testing or improvement, and guide the development of new test cases or refactoring of the code. Code coverage can also be used to compare different versions or branches of the Mendix app, and evaluate the impact of new features or changes on the overall quality of the Mendix app.

Code coverage goals and commits

Code coverage goals and commits are related because each commit can affect your code coverage, either positively or negatively. For example, if you add new features or functionality to your code, you may need to write more tests or update existing tests to cover the new code. If you refactor or optimize your code, you may be able to reduce the number or complexity of tests that you need to run on your code. If you delete or comment out some code, you may need to remove or adjust the tests that correspond to the deleted or commented code. Therefore, it is important to consider the impact of your commits on your code coverage goals, and vice versa. You should aim to make commits that enhance your code coverage, or at least maintain it at a satisfactory level. You should also check your code coverage reports and analyses after each commit, to see if you are meeting or approaching your code coverage goals, or if you need to revise or refine them. This can help you ensure that your commits and your code coverage goals are aligned and consistent, and that your Mendix app is reliable and robust.

Conclusion

Once you can measure code coverage of your automated tests, you need to figure out how to use coverage to improve the quality of your automated tests and thereby the long term quality of your Mendix app. Measuring code coverage is a means to an end, but setting and maintaining code coverage goals is a dynamic process that is part of your quality assurance strategy.

Code coverage goals can help you focus your efforts and can provide a stimulation for the entire team to reach them. Make sure to make the goals as transparent and straightforward as possible and keep the entire team involved in both setting and maintaining them. In that way code coverage can provide a good way of measuring the success of your test automation efforts.

Dick van Gorkum

Contact the author

Enter your contact details

Menu