kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mock and expect

fancsali opened this issue · 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

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

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

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?