github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/docs/assets/how-to-guides/testing-gno/counter-2.gno (about) 1 // counter-app/r/counter/counter_test.gno 2 3 package counter 4 5 import "testing" 6 7 func TestCounter_Increment(t *testing.T) { 8 // Reset the value 9 count = 0 10 11 // Verify the initial value is 0 12 if count != 0 { 13 t.Fatalf("initial value != 0") 14 } 15 16 // Increment the value 17 Increment() 18 19 // Verify the initial value is 1 20 if count != 1 { 21 t.Fatalf("initial value != 1") 22 } 23 } 24 25 func TestCounter_Decrement(t *testing.T) { 26 // Reset the value 27 count = 0 28 29 // Verify the initial value is 0 30 if count != 0 { 31 t.Fatalf("initial value != 0") 32 } 33 34 // Decrement the value 35 Decrement() 36 37 // Verify the initial value is 1 38 if count != -1 { 39 t.Fatalf("initial value != -1") 40 } 41 } 42 43 func TestCounter_Render(t *testing.T) { 44 // Reset the value 45 count = 0 46 47 // Verify the Render output 48 if Render("") != "Count: 0" { 49 t.Fatalf("invalid Render value") 50 } 51 }