What's the difference between unit testing and validation testing?

I was handed the following code inside a validation folder:

Spec.hs

-- #############################################################################
-- ########## VALIDATION TESTS                                     #############
-- ########## (DO NOT CHANGE ANYTHING)                             #############
-- ########## Note: execute tests using "stack test ploy:validate  #############
-- #############################################################################

import Test.Hspec

import Board
    ( buildBoard,
      line,
      validateFEN,
      Board,
      Cell(Empty, Piece),
      Player(Black, White),
      Pos(Pos) )
import Ploy ( gameFinished, isValidMove, listMoves, Move(Move), possibleMoves )

main :: IO ()
main = hspec $ do
    testValidateFEN
    testBuildBoard
    testLine
    testGameFinished
    testIsValidMove
    testPossibleMoves
    testListMoves

and the following inside a test folder:

Spec.hs

-- #############################################################################
-- ########### YOUR UNIT TESTS                                    ##############
-- ########### Note: execute tests using "stack test ploy:units"  ##############
-- #############################################################################

main :: IO ()
main = putStrLn "Units tests not yet implemented"

So, could someone tell me what’s the difference between those two. I should implement unit tests but it seems they are the same as validation tests.

It sez here (see V diagram) Unit testing is a phase in overall Validation.

It sez here “Validation testing is also sometimes called acceptance testing” – which is a different phase in that V diagram.

It sez here "Validation differs from verification testing, another important phase of the product development process. Verification testing is the process of confirming that the way a product performs meets the predetermined product specifications. " And unit testing is usually a phase in checking product conforms to spec.

So … there’s no clear meaning to ‘Validation testing’. Looking around at other engineering disciplines:

  • Verification testing is making sure the product conforms to spec. (So unit testing is a phase in there.)
  • Validation testing is making sure the product is fit for purpose.
  • Why need both? Usually the spec is a contractual document between a business and a software developer/package provider. Passing Verification testing means performs-to-spec and the vendor can now get paid.
  • Who wrote the spec? Probably people in the business who don’t understand big, hairy software systems. They typically fail to capture all requirements. [**] So Users get their hands on the software after the vendor has delivered it, and aren’t happy. (There have been a whole string of epic failures. Typically the vendor has swingeing penalties for ‘rework’ after delivery – that’s where they make their profit.)

In my experience, Acceptance testing (if that’s the sense that applies here) consists of ‘user stories’ – that is, following an end-to-end business process from a Customer walking in the door to them getting their new kitchen fitted out. (It looks like your Validation Tests example is like this: buildBoard then start making moves.)

It’s very common to find software passes unit tests – or appears to – but one test has left crud in the database, that only comes to light when going through the whole end-to-end process. Fixing that is rework for which the vendor won’t get paid – which is where they make their loss.

Unit tests are typically written by the developer, to show the system performs per their understanding of (probably a tiny sub-sub-section of) the spec.

[**] Specific example: an Enterprise Resource Planning system from a U.S. vendor; it supported Sales Tax, but not GST/VAT. It needed adapting for local requirements. Everybody ‘just assumed’ that because it calculated tax on sales correctly, it was fit for purpose. But it wasn’t calculating input tax on purchases, so it wasn’t correctly accounting for duties payable to the Government. Only came to light when the accountants checked the results from Acceptance testing – which of course was running late, and squeezing against the go-live date. Nice little contractual stand-off I had to negotiate.

@unlocked2412 I think you need to ask whoever handed you the code. I suspect the context is that you are taking part in a course, where the “validation tests” are written by the course author but you are also expected to write your own unit tests as part of the assignment.

1 Like

Thank you both of you.

Thank you so much. That’s exactly right. These are the validation tests:

testValidateFEN :: Spec
testValidateFEN = describe "Module Board: validateFEN ..." $ do
        it "fen has not 9 rows" $ do
            validateFEN ",,,,,,,,,/,,,,,,,,," `shouldBe` (False :: Bool)

testBuildBoard :: Spec
testBuildBoard = describe "Module Board: buildBoard ..." $ do
        it "build empty board" $ do
            buildBoard ",,,,,,,,/,,,,,,,,/,,,,,,,,/,,,,,,,,/,,,,,,,,/,,,,,,,,/,,,,,,,,/,,,,,,,,/,,,,,,,," `shouldBe` [[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty],[Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty]]

testLine :: Spec
testLine = describe "Module Board: line ..." $ do
        it "start is target" $ do
            line (Pos 'a' 1) (Pos 'a' 1) `shouldBe` ([(Pos 'a' 1)] :: [Pos])

Unfortunately, I can ask for more info since the course ended and I am helping a person with it. If that is not much trouble for you and possible, could you give me a simple example where I can see how a “unit testing” look like ?

For example, we see testBuildBoard they want to validate the output of buildBoard for an empty board. But, I see that is not enough testing. Perhaps for unit testing I should test against every possible board ?