EncodeAudioLegacy

Practice GoldenMaster on legacy with hard to test dependencies

View the Project on GitHub martinsson/EncodeAudioLegacy

Instructions

First use the setup instructions available in the README at the base of the repo change between steps using changeStep.sh or nextStep.bat

Requirements

Step 0: Check the tools

Goal : validate your tools are working

Procedure

  1. build : mvn clean compile
  2. There's a unit test: checkJUnit().
    1. It should fail.
    2. Fix it.
    3. It should pass
  3. Run code coverage you should have 0%
  4. There's a unit test: checkApprovalTestsReporter().
    1. Remove the @Ignore annotation
    2. It should open a window corresponding to your default diff tool

Acceptance tests

  1. I am able to build the project
  2. I can launch a unit test
  3. I can see the code coverage
  4. Approval Tests is able to launch a diff tool

Step 1 - String comparison using ApprovalTests

Goal: Get familiar with ApprovalTests

Bonus: find a way of covering the FileNotFoundException

Acceptance Test

You cover almost > 95% of the code

Step 2: Coverage by input parameter variation

Goal: cover as many branches as possible in CoreUtil using LegacyApprovals.lockdown()

There are tests in place, replace all of them with one single test and a test helper method. By varying the inputs you should be able to cover all but one catch clause in CoreUtil.

FYI, the InvocationTargetException you get from using LegacyApprovals is ApprovalTests way of saying that an exception was thrown by the method called by .lockdown(). You can improve the error message recorded by Approvals, by catching the exception generated by the code and returning e.getMessage()

Hints

There are 3 arguments that vary

there are files in src/test/resources that are used in the tests. You could add more of them, you could misspell a name.

Acceptance tests

  1. There is only one test method
  2. All branches (except IOException in CoreUtil) are covered

Step 3 - Serializing a complex type

Goal: Be able to compare a complex graph of nested objects

Use 'new XStream().toXml(someObject)' instead of 'someObject.toString()'

Acceptance Test

No use of IfluxTmlg.toString()

Step 4 - Mocking a webservice

Goal: Setup a webserver to serve a file

All tests are failing because the code now tries to download a file from an external webserver. Check the logs for the details of the missing file.

Configure Moco's 'server' object to respond with one of the source files in src/test/resources

Acceptance Test

The test passes without exception for atleast some of the combinations of input arguments

Step 5 - Capturing side effects

Goal: Capture the side effects and use them in the comparison

Files are encoded and saved to disk for access by 3rd party, capture for instance the names of all encoded files, append the file names to the result. The files are saved to the 'tmpDir' that is initialised in the test

Acceptance Test

Use both the result of the function call and the side effects for approving.