shunit2 icon indicating copy to clipboard operation
shunit2 copied to clipboard

Mock and expect

Open fancsali opened this issue 1 year ago • 3 comments

I was just wondering, what is the preferred way of doing something like the example below (which doesn't seem to work):

# my_command.test.sh

# Test my_command in fact does call my_other_command
. src/my_command.sh # Assuming my_command is a function

CALLS_COUNT=0

my_other_command {
  # do something
  CALLS_COUNT=$(( CALLS_COUNT + 1 ))
}

tesMyCommand() {
  my_command

  assertEquals 1 $CALLS_COUNT
}

NOTE: This is assumed to be called like this: shunit2 my_command.test.sh

fancsali avatar Feb 26 '23 15:02 fancsali

Hi what is exactly not working, can you provide the output?

williamdes avatar Feb 26 '23 19:02 williamdes

Something seems to be running in a sub-shell, and when I test the value it's always 0;

fancsali avatar Feb 28 '23 15:02 fancsali

Something seems to be running in a sub-shell, and when I test the value it's always 0;

Okay, would you mind posting the output of your test script?

williamdes avatar Feb 28 '23 20:02 williamdes