You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2023/11/03 08:38:09 UTC

(groovy-website) branch asf-site updated (faa0069 -> ea46a59)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a change to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git


    from faa0069  remove draft status
     new 8f8b32f  add testing examples
     new ea46a59  add testing examples

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/site/blog/community-over-code-na-2023.adoc |  77 ++++++++++++++++++++-
 site/src/site/blog/img/TestingJava1.png            | Bin 0 -> 60836 bytes
 site/src/site/blog/img/TestingJava2.png            | Bin 0 -> 115009 bytes
 site/src/site/blog/img/TestingJava3.png            | Bin 0 -> 134807 bytes
 site/src/site/blog/img/TestingJava4.png            | Bin 0 -> 90724 bytes
 site/src/site/blog/img/TestingJava5.png            | Bin 0 -> 107259 bytes
 site/src/site/blog/img/TestingJava6.png            | Bin 0 -> 196600 bytes
 7 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 site/src/site/blog/img/TestingJava1.png
 create mode 100644 site/src/site/blog/img/TestingJava2.png
 create mode 100644 site/src/site/blog/img/TestingJava3.png
 create mode 100644 site/src/site/blog/img/TestingJava4.png
 create mode 100644 site/src/site/blog/img/TestingJava5.png
 create mode 100644 site/src/site/blog/img/TestingJava6.png


(groovy-website) 02/02: add testing examples

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git

commit ea46a59bb27b54b71da9558cd10af26fe164622c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Nov 3 18:37:53 2023 +1000

    add testing examples
---
 site/src/site/blog/img/TestingJava1.png | Bin 0 -> 60836 bytes
 site/src/site/blog/img/TestingJava2.png | Bin 0 -> 115009 bytes
 site/src/site/blog/img/TestingJava3.png | Bin 0 -> 134807 bytes
 site/src/site/blog/img/TestingJava4.png | Bin 0 -> 90724 bytes
 site/src/site/blog/img/TestingJava5.png | Bin 0 -> 107259 bytes
 site/src/site/blog/img/TestingJava6.png | Bin 0 -> 196600 bytes
 6 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/site/src/site/blog/img/TestingJava1.png b/site/src/site/blog/img/TestingJava1.png
new file mode 100644
index 0000000..ac7f80d
Binary files /dev/null and b/site/src/site/blog/img/TestingJava1.png differ
diff --git a/site/src/site/blog/img/TestingJava2.png b/site/src/site/blog/img/TestingJava2.png
new file mode 100644
index 0000000..a1900cd
Binary files /dev/null and b/site/src/site/blog/img/TestingJava2.png differ
diff --git a/site/src/site/blog/img/TestingJava3.png b/site/src/site/blog/img/TestingJava3.png
new file mode 100644
index 0000000..785a0d6
Binary files /dev/null and b/site/src/site/blog/img/TestingJava3.png differ
diff --git a/site/src/site/blog/img/TestingJava4.png b/site/src/site/blog/img/TestingJava4.png
new file mode 100644
index 0000000..dfb28fb
Binary files /dev/null and b/site/src/site/blog/img/TestingJava4.png differ
diff --git a/site/src/site/blog/img/TestingJava5.png b/site/src/site/blog/img/TestingJava5.png
new file mode 100644
index 0000000..2979f72
Binary files /dev/null and b/site/src/site/blog/img/TestingJava5.png differ
diff --git a/site/src/site/blog/img/TestingJava6.png b/site/src/site/blog/img/TestingJava6.png
new file mode 100644
index 0000000..90707ca
Binary files /dev/null and b/site/src/site/blog/img/TestingJava6.png differ


(groovy-website) 01/02: add testing examples

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git

commit 8f8b32f7cb8e6a76e9ab877254628afe62eb28e5
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Nov 3 18:37:06 2023 +1000

    add testing examples
---
 .../src/site/blog/community-over-code-na-2023.adoc | 77 +++++++++++++++++++++-
 1 file changed, 76 insertions(+), 1 deletion(-)

diff --git a/site/src/site/blog/community-over-code-na-2023.adoc b/site/src/site/blog/community-over-code-na-2023.adoc
index 2c01326..33f76d3 100644
--- a/site/src/site/blog/community-over-code-na-2023.adoc
+++ b/site/src/site/blog/community-over-code-na-2023.adoc
@@ -198,10 +198,85 @@ But of course, you aren't limited to just that list.
 The next two talks were aimed at Java developers who wanted to understand how
 they could use Groovy for their development or testing needs.
 
-Groovy for Java Developers
+The next talk was by https://www.linkedin.com/in/jeffscottbrown/[Jeff Scott Brown] on
+_Groovy for Java Developers_. Jeff covered a range of topics including:
+
+* Groovy optional typing
+* Groovy properties
+* Groovy script syntax
+* Evolving Java source to Groovy
+* Special features of Groovy
+* Groovy extension methods for Groovy and Java classes
 
 The next talk was
 https://speakerdeck.com/paulk/property-based-testing[Testing your Java with Groovy, Spock, JUnit5, Jacoco, Jqwik and Pitest].
+This talk covered a common scenario of using Groovy tests with Java production code, though most of the content
+is applicable for production code in other JVM languages (including Groovy!) too.
+It also showed examples of a few advanced tools you might want to consider as part of your testing toolkit.
+
+The central example for the talk was based around what initially appears to be a very
+simple mathematical calculation originally implemented using the following Java code:
+
+image:img/TestingJava1.png[Buggy code,80%]
+
+We write a Groovy test using the https://spockframework.org/[Spock] testing framework which
+at first glance seems to indicate our initial implementation is correct since all the tests
+pass and we have 100% test coverage.
+
+image:img/TestingJava2.png[Code coverage,90%]
+
+But this is 100% line and branch coverage but doesn't reflect 100% state coverage.
+We can illustrate this by adding one more test case, which now fails:
+
+image:img/TestingJava3.png[Add fault revealing test case,90%]
+
+It turns out there was one edge case the initial implementation didn't cater
+for but it is simple enough to fix:
+
+image:img/TestingJava4.png[Corrected algorithm,90%]
+
+We now have all test cases passing and still 100% coverage.
+
+The moral of the story is that 100% line and branch coverage isn't sufficient
+to ensure a correct implementation. You should try to add test cases until
+you think the problem domain is fully tested. The rest of the talk looked
+at two advanced tools which could assist you in finding test case deficiencies.
+
+The https://pitest.org/[Pitest tool] is a mutation testing tool.
+Understanding how it works and how it can help is a little mind-bending at first.
+Pitest mutates your production code and then re-runs your test suite.
+If the test suite still passes, i.e. the mutant survives, it represents a possible code smell.
+
+Often it means that your test suite isn't complete enough to kill the mutant,
+and you should add some more test cases.
+But mutation testing is not an exact science, if a mutant survives,
+it could mean there is a missing test case,
+it could mean there is a flaw in the existing test cases,
+it could mean there is a bug in the implementation code,
+or it could be a false positive.
+
+Running the tool on the faulty implementation when we had 3 test cases,
+indeed reveals some surviving mutations and analysis indicates that indeed the mutations
+correspond to the faulty edge case:
+
+image:img/TestingJava5.png[Pitest result,90%]
+
+This should direct us to add the additional test case like we did manually earlier
+and this would hopefully have forced us to discover the bug.
+
+Running the tool on the fixed implementation showed an improvement
+but still indicated a possible code smell. That finding reflects that
+for our fixed implementation, that `c > Math.min(a, b)` and `c >= Math.min(a, b)`
+are equivalent, even though in the general case it might mean
+an edge case wasn't being tested. So mutation testing can certainly be
+useful but often requires human analysis to rule out any false positives.
+
+The other tool examined was https://jqwik.net/[Jqwik], a property-based testing tool.
+Such tools check that certain properties hold when exercising the implementation
+under test with random data. Indeed, such testing also reveals the flaw in the
+original code, with no flaw found in the fixed code.
+
+image:img/TestingJava6.png[Jqwik result,90%]
 
 === Kubernetes and Groovy