Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve automated test coverage #114

Open
MarkEWaite opened this issue Sep 30, 2022 · 7 comments
Open

Improve automated test coverage #114

MarkEWaite opened this issue Sep 30, 2022 · 7 comments
Labels
enhancement Improvement or new feature good first issue Well suited for inexperienced contributors

Comments

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 30, 2022

Increase automated test coverage

Automated test coverage of the embeddable build status plugin is quite low. Improve the automated test coverage by submitting pull requests with new automated tests.

Review current coverage

Review the current test coverage with the commands:

Linux

$ mvn -P enable-jacoco clean install jacoco:report
$ xdg-open target/site/jacoco/index.html

Windows

C:\Users\Yourname > mvn -P enable-jacoco clean install jacoco:report
C:\Users\Yourname > start target\site\jacoco\index.html

More information is in the "code coverage" section of the contributing guide.

Create a new test for a class that is not well covered

Most integrated development environments have tools that will create a test stub that is a good beginning. Apache Netbeans has "Create / Update tests" . JetBrains IntelliJ has "Create tests". Visual Studio Code has the "Extension Pack for Java".

Use the IDE or your own coding to create a test for one of the classes that is not well covered by tests.

Keep the test small so that the pull request is easy to review.

@MarkEWaite MarkEWaite added enhancement Improvement or new feature good first issue Well suited for inexperienced contributors labels Sep 30, 2022
@adamtkac
Copy link

adamtkac commented Oct 2, 2022

Hi @MarkEWaite could you assign me to this issue? Appreciate any initial pointers for working on this as a first time contributor. Thanks in advance.

@MarkEWaite
Copy link
Contributor Author

MarkEWaite commented Oct 3, 2022

@adamtkac I'm delighted that you're willing to contribute. There is enough work on this topic that I don't bother to assign it to a single person. You can start the work and submit a pull request. See the Jenkins gitter Hacktoberfest chat channel for a recent discussion about assessing test coverage of a plugin and writing new unit tests based on that result.

The steps are:

  • Identify larger Java classes with very little test coverage from the ci.jenkins.io test coverage report (look at the line coverage report to identify the larger classes with low coverage
  • Install the necessary tools (git, Java 11, Apache Maven) as described in "Preparing for plugin development"
  • Checkout a local copy of the repository with git clone https://github.com/jenkinsci/embeddable-build-status-plugin.git
  • Build and run automated tests locally with mvn -P enable-jacoco clean install jacoco:report
  • Review the locally generated coverage report in target/site/jacoco/index.html to identify untested classes and statements
  • Use your integrated development environment (Visual Studio Code, Apache Netbeans, IntelliJ, or Eclipse) to generate test stubs for one of the untested classes
  • Add test details to one of the stubs, delete the other stubs
  • Run the test and confirm that the test compiles and that it passes
  • Submit a pull request so that it can be reviewed and improved if necessary

@adamtkac
Copy link

adamtkac commented Oct 3, 2022

Thank you for your answer. It is possible to divide issue to partial issues, depending on parts of code which needs to be covered first? I will start do my best as soon as I can.

@MarkEWaite
Copy link
Contributor Author

Thank you for your answer. It is possible to divide issue to partial issues, depending on parts of code which needs to be covered first? I will start do my best as soon as I can.

Yes, you're welcome to create additional issues that track specific classes where you are focusing implementation.

kalarani-tw added a commit to kalarani-tw/embeddable-build-status-plugin that referenced this issue Oct 28, 2022
kalarani-tw added a commit to kalarani-tw/embeddable-build-status-plugin that referenced this issue Oct 29, 2022
kalarani-tw added a commit to kalarani-tw/embeddable-build-status-plugin that referenced this issue Oct 29, 2022
kalarani-tw added a commit to kalarani-tw/embeddable-build-status-plugin that referenced this issue Oct 29, 2022
MarkEWaite added a commit that referenced this issue Oct 30, 2022
Improve automated test coverage #114 - Add test for classes in default package
MarkEWaite added a commit that referenced this issue Oct 30, 2022
Improve automated test coverage #114 - Add test for classes in extensions package
@wliao008
Copy link

mvn -P enable-jacoco clean install jacoco:report ran successfully for me once, on subsequent runs I've been getting the following error (w/o any change), mvn test also produced the same sort of error. i have java 11, macos 12.3, jenkins 2.361.4, wonder if anyone seen this before.

[ERROR] Failures:                                                                                                                [605/1944]
[ERROR]   PublicBuildStatusActionTest.testDoIconBuildAfter:104
Expected: a string containing "<svg "
     but: was "<html><body>
<h1>404 Not Found</h1>
<p>Stapler processed this HTTP request as follows, but couldn't find the resource to consume the request
<pre>
-&gt; evaluate(&lt;hudson.model.Hudson@22513da2&gt; :hudson.model.Hudson,"/buildStatus/icon")
-&gt; evaluate(((StaplerProxy)&lt;hudson.model.Hudson@22513da2&gt;).getTarget(),"/buildStatus/icon")
-&gt; evaluate(&lt;hudson.model.Hudson@22513da2&gt;.getDynamic("buildStatus",...),"/icon")
            [email protected]("buildStatus",...)==null. Back tracking.
-&gt; evaluate(((StaplerFallback)&lt;hudson.model.Hudson@22513da2&gt;).getStaplerFallback(),"/buildStatus/icon")
-&gt; evaluate(&lt;hudson.model.AllView@65ca8da2[view/all/]&gt; :hudson.model.AllView,"/buildStatus/icon")
-&gt; evaluate(&lt;hudson.model.AllView@65ca8da2[view/all/]&gt;.getDynamic("buildStatus",...),"/icon")
            hudson.model.AllView@65ca8da2[view/all/].getDynamic("buildStatus",...)==null. Back tracking.
<font color=red>-&gt; No matching rule was found on &lt;hudson.model.AllView@65ca8da2[view/all/]&gt; for "/buildStatus/icon"</font>
</pre>
<p>&lt;hudson.model.AllView@65ca8da2[view/all/]&gt; has the following URL mappings, in the order of preference:<ol>
<li>                                                                                                                                       If path ends without '/' insert it

@MarkEWaite
Copy link
Contributor Author

I've not seen that failure before. I don't have access to a macOS machine, but I confirmed that the tests run as expected multiple times on a FreeBSD 13.1 machine (closest thing I have to macOS). The web response is definitely a Jenkins response. I don't know why it would report that the resource cannot be found.

@wliao008
Copy link

Thanks Mark, I thought it might be related to SECURITY-595, because I did also run into 404 with badge/text where I had to add the whitelisting to stapler-whitelist.txt for it to work:

method org.jenkinsci.plugins.badge.actions.RunBadgeAction doText

But I'm not sure where to add this while running unittest...Im gonna try couple things see if I can get it working..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement or new feature good first issue Well suited for inexperienced contributors
Projects
None yet
Development

No branches or pull requests

3 participants