Giter VIP home page Giter VIP logo

junit-coverage-report's Introduction

Pytest: JUnit Coverage Report

licence version

Extending Junit Coverage Report for monorepo support

Add a pull request comment with tests results and coverage report.
Works with junit and coverage XML output from pytest.

python3 -m pytest --cov-report "xml:reports/coverage/coverage.xml" --junitxml="reports/unit/unit.xml"

How to use

Add this action to your GitHub workflow as follows:

- name: Test Reports
  uses: xportation/junit-coverage-report@main
  with:
    junit-path: ./reports/unit/unit.xml  
    coverage-path: ./reports/coverage/coverage.xml

You can also define github-token used for the Github comments API.

- name: Custom Reports
  uses: xportation/junit-coverage-report@main
  with:
    github-token: {{ $secrets.your_secret }}   
    junit-path: ./reports/unit/unit.xml  
    coverage-path: ./reports/coverage/coverage.xml

Default report:

Collapsed

Collapsed

Expanded

Expanded

Custom reports

You can define custom reports using Handlebars templates.
Just add the template-path with the file url.

- name: Custom Reports
  uses: xportation/junit-coverage-report@main
  with:
    template-path: ./reports/custom_template.html   
    junit-path: ./reports/unit/unit.xml  
    coverage-path: ./reports/coverage/coverage.xml

Data Schema

The data schema provided for the template rendering:

{
  coverage: {
    badge,
    total: {
      stmts,
      miss,
      cover
    },
    items: [
      {
        fileUrl, 
        filename, 
        stmts, 
        miss, 
        cover, 
        missing: [
          {
            range, 
            url
          }
        ]
      }
    ]
  }, 
  junit: {
    tests, 
    skipped, 
    failures, 
    errors, 
    time, 
    failuresItems: [
      {
        filename, 
        message
      }
    ]
  } 
}

Default Template

The default template is below:

<img alt="Coverage" src="{{coverage.badge}}" />
<br/>
<details>
    <summary>Coverage Report</summary>
    <table>
        <tr>
            <th>File</th>
            <th>Stmts</th>
            <th>Miss</th>
            <th>Cover</th>
            <th>Missing</th>
        </tr>
        <tbody>
            {{#coverage.items}}
            <tr>
                <td><a href="{{fileUrl}}">{{filename}}</a></td>
                <td>{{stmts}}</td>
                <td>{{miss}}</td>
                <td>{{cover}}</td>
                <td>
                {{#missing}}
                    <a href="{{url}}">{{range}}</a> 
                {{/missing}}
                </td>
            </tr>
            {{/coverage.items}}
            <tr>
                <td><b>TOTAL</b></td>
                <td><b>{{coverage.total.stmts}}</b></td>
                <td><b>{{coverage.total.miss}}</b></td>
                <td><b>{{coverage.total.cover}}</b></td>
                <td>&nbsp;</td>
            </tr>
        </tbody>
    </table>
</details>
<br/> 
<table>
    <tbody>
        <tr>
            <td><strong>Tests</strong></td>
            <td><strong>Skipped</strong></td>
            <td><strong>Failures</strong></td>
            <td><strong>Errors</strong></td>
            <td><strong>Time</strong></td>
        </tr>
        <tr>
            <td>{{junit.tests}}</td>
            <td>{{junit.skipped}} ๐Ÿ’ค</td>
            <td>{{junit.failures}} โŒ</td>
            <td>{{junit.errors}} ๐Ÿ”ฅ</td>
            <td>{{junit.time}} โฑ</td>
        </tr>
    </tbody>
</table>
<br/>
{{#if junit.failuresItems}}
<details>
    <summary>Unit Failures</summary>
    <table>
        <tr>
            <th>Test</th>
            <th>Message</th>
        </tr>
        <tbody>
            {{#junit.failuresItems}}
            <tr>
                <td>{{filename}}</td>
                <td><code>{{{message}}}</code></td>
            </tr>
            {{/junit.failuresItems}}
        </tbody>
    </table>
</details>
{{/if}}

Alternative GH Action

This project was strongly inspired by the Pytest Coverage Comment
It's a great alternative project. You should consider it ๐Ÿ–ค.

junit-coverage-report's People

Contributors

xportation avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.