1.
Introduction
To assist Java programming educations, we have developed a Web-based Java Programming Learning Assistant System (JPLAS) [1] that provides the code writing problem to write a source code for a given assignment. The correctness is verified through running the test code on JUnit as the test-driven development (TDD) method [2]. In  Java  programming, the polymorphism encapsulation, inheritance and are concepts object-oriented fundamental as the programming (OOP) language that every student should understand and freely uses them. Previously, we proposed the informative test code approach for the code writing problem to help students studying these concepts through the code writing problem [3]. The informative test code describes names of class, methods and variables, access modifier, data types, exception handling, behaviors and class inheritance. By writing a source code to pass the informative test code , a student is expected to write a source code that adopts the same concepts of the model source code. Unfortunately, the previous test code does not test private variables for encapsulation , and variables/methods in super/sub classes for inheritance and polymorphism. As a result, it allows students to write the source codes that pass the tests but do not properly use the three concepts. In this paper, we improve the informative test code by adopting the library functions in Java to test private variables and variables/methods in super/sub classes. For evaluations, we generated the improved informative test codes for Que and Stack which follow the First-in-First- Out and Last-in Fast-Out. Then, we asked eight students to write the source codes, where they completed them using the three concepts. Proposal of Improved Informative Test Code In this section, we improve the informative test code for three concepts [4]-[6].
2.1 Informative
Test
Code
Que
Using
for
Encapsulation
The following test code 1 shows a part of the test code that is generated from the source code for Que using encapsulation. In this source code, the three variables content, tail , and head are declared as private to be hidden from other classes. content stores the string or integer values, and tail and head store the first and last index number of the stored values in content . Then, three methods, push, empty , and pop are declared as public. push inserts a new value to content, pop retrieves the bottom value of the content , and empty returns true if content is empty. content can be accessed through pop and push methods. test code 1 l: 2: ...
//check the value of private variables int tail=(int) f2.get(q); assertEquals(2, tail); //check the behaviors of pop and empty assertEquals(10,q.pop());
assertEquals("a",q.pop()); In test code 1 , library functions, setAccessible and get , test the values of the private variables, tail, head , in lines 8, 9, 12, 13, 18 and 19. Then, pop tests the values of the private variable, content , in lines 15 and 16.
2.2 Informative
Test
Code
for
Stack
Using
Inheritance and polymorphism
The following test code 2 shows a part of the test code that is generated from the source code for Que using inheritance and polymorphism. In the source code, the variables, content , tail , and head , and the methods, empty and push , are inherited from Que . Then, pop is overwritten in Stack from that in Que. In the test code 2 , the library function, getSuperClass, tests the super class in line 5. Then, the names of the variables, content , tail , and head , and the methods, push , pop , and empty , in the super class Que are described and tested in lines 6 to 11. Then, the names, access modifier and data types of pop in the sub class Stack are also described and tested in lines 12 to 14. test code 2 1: 2: 3: public void test() throws Exception { 4: Stack s = new Stack(); Class<?> parentClass= s.getClass().getSuperClass(); 5: //check variable name 6: Field fl=parentClass().getDeclaredField("content"); 7: Field f2=parentClass().getDeclaredField("tail"); 8: Field f2=parentClass().getDeclaredField(''head''); Method m1=parentClass().getDeclaredMethod 9: ("empty",null); Method m2=parentClass().getDeclaredMethod 10: ("pop",null); Method m3=parentClass().getDeclaredMethod 11: ("push",Object.class); Method mstack=s.getClass().getDeclaredMethod 12: ("pop",null); assertEquals(mstack.getModifier(), 13: Modifier.PULIC); assertEquals(mstack.getReturnType(),Object.class); 14: 15: } ... 16:
3.
Evaluation
In this section, we evaluate the improved informative test codes through applications to eight students in our group. First we prepared the informative test codes for Que and Stack.
Then, we asked them to write the source codes for Que and Stack using the improved informative test codes. Table 1 shows the metric results of the eight source codes for Que. In any source code, NOC is 1 and NOM is 3. They have the same number of classes and methods. This reason is that any source is implemented using the class and methods given in the test code. They also have the good metrics for VG, NBD, and LCOM, where VG is 1- 2, NBD is 1 and LCOM is 0.3- 0.6 respectively.
Table 2 shows the metric results of the eight source codes for Stack. In any code, NOC is 1 and NOM is 1. They have the same number of classes and methods by implemented using class and methods in test code. They also have good metrics for VG, NBD and LCOM where VG is 1-2, NBD is 1 and LCOM is 0 respectively. This evaluation results show that the students completed high-quality source codes using three concepts for Que and Stack by following the intentions of the test codes. However, in both code, larger VG and MLC appear since the codes are complex and hard to be modified. The current test code cannot test the code quality directly.
4.
Conclusion
In this paper, we proposed the improved informative test code for the code writing problem in JPLAS to help the students studying the encapsulation , inheritance , and polymorphism. We evaluated the effectiveness through the test codes for Que and Stack using three concepts. In future works, we will improve the test code to test the quality more and generate test codes using other source codes for the three concepts to assign them to students.