大家好,我的问题如下:我想为我写的一个类写一个测试单元。为此,我有以下 Junit 代码:
1 package ts;
2 import ts.TransitionSystem;
3 import ts.ConcreteTransitionSystem;
4 import java.util.Set;
5 import java.util.HashSet;
6 import java.util.HashMap;
7
8 import org.junit.Test;
9 public class TransitionSystemTest {
10
11 @Test
12 public void addInitialTest () {
13 TransitionSystem ts = new ConcreteTransitionSystem();
14 ts.addInitialState("test");
15 assertTrue(ts._initialStates.contains("test"));
16 assertTrue(ts._states.get("s0").isEmpty());
17 }
18
19 }
我的班级如下所示:
1 package ts;
2
3 import java.util.Set;
4 import java.util.HashSet;
5 import java.util.HashMap;
6 import ts.TransitionSystem;
7
8 public class ConcreteTransitionSystem implements TransitionSystem {
9 Set<String> aps;
10 HashMap<String, Set<String>> _states;
11 Set<String> _initialStates;
12
13 public void addInitialState(String s0) {
14 Set<String> sucessors = new HashSet<String>();
15 this._states.put(s0, sucessors);
16 this._initialStates.add(s0);
17 }
18 }
它得到的错误如下:
TransitionSystemTest.java:15: error: cannot find symbol
[javac] assertTrue(ts._initialStates.contains("test"));
[javac] ^
[javac] symbol: variable _initialStates
[javac] location: variable ts of type TransitionSystem
和
TransitionSystemTest.java:16: error: cannot find symbol
[javac] assertTrue(ts._states.get("s0").isEmpty());
[javac] ^
[javac] symbol: variable _states
[javac] location: variable ts of type TransitionSystem
我无法弄清楚问题所在。有任何想法吗?