UMM-CSci-3601 / 3601-iteration-template

This template repository is used as a starting point for course projects in CSci 3601: Software Design and Development at the University of Minnesota Morris. It includes an Angular client along with a Javalin server and Mongo database.
MIT License
0 stars 9 forks source link

Add Cypress code coverage #925

Open NicMcPhee opened 2 years ago

NicMcPhee commented 2 years ago

Cypress (now?) supports code coverage, and it looks like we might even be able to combine Cypress and Karma coverage into a single report. That could be really nice, because then we could set limits on combined coverage and let the teams decide how to best achieve the desired coverage. The one possible downside is that we might see a serious shift to almost entirely E2E tests since (I'm guessing) they'll provide the most coverage for the least amount of effort. That said, I suspect there are going to be edge cases and error conditions that will still be easier to test for with unit tests.

I was able use follow the changes in "Implementing code coverage with Angular and Cypress" on one of the final projects from S22, but that broke a lot of tests. I was able to fix most of them by adding "proxyConfig": "proxy.conf.json" to projects -> client -> architect -> serve-coverage -> options in angular.json. The proxy.conf.json file is where we say that calls to /api should go to port 4567, and that what was breaking for most of the tests. (I think the remaining broken tests are due to some slow code on their end, although I'm not sure.)

Even with a few tests that still fail, the E2E coverage was very good:

=============================== Coverage summary ===============================
Statements   : 89.73% ( 236/263 )
Branches     : 83.48% ( 91/109 )
Functions    : 91.93% ( 114/124 )
Lines        : 88.05% ( 199/226 )
================================================================================

For comparison, here's the Karma coverage from that project:

=============================== Coverage summary ===============================
Statements   : 87.13% ( 237/272 )
Branches     : 86.66% ( 39/45 )
Functions    : 80.9% ( 89/110 )
Lines        : 85.65% ( 203/237 )
================================================================================

The E2E coverage is a little to substantially better than the Karma coverage in every category except for branches, where it's slightly worse (83% vs 87%). If I took the time to combine the two, I'm guessing that we'd have over 90% coverage in all four categories, which would be super spiffy.

Some potentially useful resources:

kklamberty commented 1 year ago

It might also be worth knowing that Cypress can run component tests as well as e2e tests. I thought we might want to consider using Cypress for both just to reduce the number of different things the students have to figure out.

kklamberty commented 1 year ago

There is also this "Real World App" with Cypress testing in it that I didn't know about until at least halfway through Spring 2023. Seems like a nice resource: Cypress Real World App