summaryrefslogtreecommitdiff
path: root/deps/Unity/examples/example_2/test
diff options
context:
space:
mode:
Diffstat (limited to 'deps/Unity/examples/example_2/test')
-rw-r--r--deps/Unity/examples/example_2/test/TestProductionCode.c64
-rw-r--r--deps/Unity/examples/example_2/test/TestProductionCode2.c33
-rw-r--r--deps/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c9
-rw-r--r--deps/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c11
-rw-r--r--deps/Unity/examples/example_2/test/test_runners/all_tests.c12
5 files changed, 129 insertions, 0 deletions
diff --git a/deps/Unity/examples/example_2/test/TestProductionCode.c b/deps/Unity/examples/example_2/test/TestProductionCode.c
new file mode 100644
index 0000000..b8fb95c
--- /dev/null
+++ b/deps/Unity/examples/example_2/test/TestProductionCode.c
@@ -0,0 +1,64 @@
+#include "ProductionCode.h"
+#include "unity.h"
+#include "unity_fixture.h"
+
+TEST_GROUP(ProductionCode);
+
+//sometimes you may want to get at local data in a module.
+//for example: If you plan to pass by reference, this could be useful
+//however, it should often be avoided
+extern int Counter;
+
+TEST_SETUP(ProductionCode)
+{
+ //This is run before EACH TEST
+ Counter = 0x5a5a;
+}
+
+TEST_TEAR_DOWN(ProductionCode)
+{
+}
+
+TEST(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode)
+{
+ //All of these should pass
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(2));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1));
+}
+
+TEST(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken)
+{
+ // You should see this line fail in your test summary
+ TEST_ASSERT_EQUAL(1, FindFunction_WhichIsBroken(34));
+
+ // Notice the rest of these didn't get a chance to run because the line above failed.
+ // Unit tests abort each test function on the first sign of trouble.
+ // Then NEXT test function runs as normal.
+ TEST_ASSERT_EQUAL(8, FindFunction_WhichIsBroken(8888));
+}
+
+TEST(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue)
+{
+ //This should be true because setUp set this up for us before this test
+ TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable());
+
+ //This should be true because we can still change our answer
+ Counter = 0x1234;
+ TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable());
+}
+
+TEST(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain)
+{
+ //This should be true again because setup was rerun before this test (and after we changed it to 0x1234)
+ TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable());
+}
+
+TEST(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed)
+{
+ //Sometimes you get the test wrong. When that happens, you get a failure too... and a quick look should tell
+ // you what actually happened...which in this case was a failure to setup the initial condition.
+ TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable());
+}
diff --git a/deps/Unity/examples/example_2/test/TestProductionCode2.c b/deps/Unity/examples/example_2/test/TestProductionCode2.c
new file mode 100644
index 0000000..d9f4efe
--- /dev/null
+++ b/deps/Unity/examples/example_2/test/TestProductionCode2.c
@@ -0,0 +1,33 @@
+#include "ProductionCode2.h"
+#include "unity.h"
+#include "unity_fixture.h"
+
+TEST_GROUP(ProductionCode2);
+
+/* These should be ignored because they are commented out in various ways:
+#include "whatever.h"
+*/
+//#include "somethingelse.h"
+
+TEST_SETUP(ProductionCode2)
+{
+}
+
+TEST_TEAR_DOWN(ProductionCode2)
+{
+}
+
+TEST(ProductionCode2, IgnoredTest)
+{
+ TEST_IGNORE_MESSAGE("This Test Was Ignored On Purpose");
+}
+
+TEST(ProductionCode2, AnotherIgnoredTest)
+{
+ TEST_IGNORE_MESSAGE("These Can Be Useful For Leaving Yourself Notes On What You Need To Do Yet");
+}
+
+TEST(ProductionCode2, ThisFunctionHasNotBeenTested_NeedsToBeImplemented)
+{
+ TEST_IGNORE(); //Like This
+}
diff --git a/deps/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c b/deps/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c
new file mode 100644
index 0000000..6fcc3b1
--- /dev/null
+++ b/deps/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c
@@ -0,0 +1,9 @@
+#include "unity.h"
+#include "unity_fixture.h"
+
+TEST_GROUP_RUNNER(ProductionCode2)
+{
+ RUN_TEST_CASE(ProductionCode2, IgnoredTest);
+ RUN_TEST_CASE(ProductionCode2, AnotherIgnoredTest);
+ RUN_TEST_CASE(ProductionCode2, ThisFunctionHasNotBeenTested_NeedsToBeImplemented);
+} \ No newline at end of file
diff --git a/deps/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c b/deps/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c
new file mode 100644
index 0000000..41a416a
--- /dev/null
+++ b/deps/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c
@@ -0,0 +1,11 @@
+#include "unity.h"
+#include "unity_fixture.h"
+
+TEST_GROUP_RUNNER(ProductionCode)
+{
+ RUN_TEST_CASE(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode);
+ RUN_TEST_CASE(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken);
+ RUN_TEST_CASE(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue);
+ RUN_TEST_CASE(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain);
+ RUN_TEST_CASE(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed);
+} \ No newline at end of file
diff --git a/deps/Unity/examples/example_2/test/test_runners/all_tests.c b/deps/Unity/examples/example_2/test/test_runners/all_tests.c
new file mode 100644
index 0000000..e706ece
--- /dev/null
+++ b/deps/Unity/examples/example_2/test/test_runners/all_tests.c
@@ -0,0 +1,12 @@
+#include "unity_fixture.h"
+
+static void RunAllTests(void)
+{
+ RUN_TEST_GROUP(ProductionCode);
+ RUN_TEST_GROUP(ProductionCode2);
+}
+
+int main(int argc, const char * argv[])
+{
+ return UnityMain(argc, argv, RunAllTests);
+}