beanshell / beanshell

Beanshell scripting language
Apache License 2.0
815 stars 183 forks source link

Documentation Writing unit tests #72

Open nickl- opened 5 years ago

nickl- commented 5 years ago

I configured coverage reports with the CI build, you may have noticed the new badge on the project front page: codecov

I would like this to reach a more acceptable percentile before we roll the release. Please assist if you have some time available so we can wrap this up.

There are two ways to contribute unit tests.

The new old bsh test scripts: This has become my favourite platform, no need to eval scripts from java strings. Just script bsh like it was meant to. Many new features like junit asserts and hamcrest matchers, improved error reporting and running single script tests has brought it on par with a modern testing framework.

To get started you can copy. paste and rename the template script to src/test/resources/test-scripts/ and run your script with the mvn command line:

$ mvn test -Dtest=BshScriptTestCase -Dscript=your_test_script.bsh

The template is documented and you can look at some the newer test scripts as examples.

Or if you prefer... The good old faithful junit tests: You can copy, paste and rename one of the existing tests, into src/test/java/bsh/. Some of the newer tests may make better templates, try TryStatementTest, FinalModifierTest or TypeParametersTest, these all use theTestUtil convenience class.

Surefire (maven junit test runner plugin) includes the following names by default which you may consider when naming your tests:

**/Test*.java - includes all of its subdirectories and all java filenames that start with "Test". **/*Test.java - includes all of its subdirectories and all java filenames that end with "Test". **/*TestCase.java - includes all of its subdirectories and all java filenames that end with "TestCase".

You can single out your test with the following command:

$ mvn test -Dtest=TestClassName
nickl- commented 5 years ago

Codecov reports 69% coverage as of the last commit, although the jacoco report generated during the build reports a 77% coverage and I can't find any discrepancies on the actual hits per source file so not sure where the difference comes from.

...anyway we are slowly bu surely getting there. Whoop Whoop!!! \o/

Everyone is still welcome, if you have some spare time to roll an additional test or two, makes you awesome.

Much joyce...

nickl- commented 1 year ago

Seems tagging an issues with "help wanted" is one sure way to get it ignored.

We are currently up to 74% coverage, which is pretty good in my books and proves that what we are doing is working. InnerClassTest.java.txt

Instead of closing, this has good information for documentation on writing unit tests so tagging it an such.