webwork and junit l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
WeBWorK and JUnit PowerPoint Presentation
Download Presentation
WeBWorK and JUnit

Loading in 2 Seconds...

play fullscreen
1 / 31

WeBWorK and JUnit - PowerPoint PPT Presentation


  • 118 Views
  • Uploaded on

WeBWorK and JUnit. an automated code grading system. Summary. Introduction JUnit basics JUnit/WeBWorK extension sample session Future directions. Introduction. Want to make a system to automatically grade small java assignments usable from the very first day of class little startup

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'WeBWorK and JUnit' - izzy


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
webwork and junit

WeBWorK and JUnit

an automated code grading system

summary
Summary
  • Introduction
  • JUnit basics
  • JUnit/WeBWorK extension
  • sample session
  • Future directions
introduction
Introduction
  • Want to make a system to
    • automatically grade small java assignments
    • usable from the very first day of class
      • little startup
    • provide appropriate feedback at a more accessible level than compiler errors
automatic grading
Automatic grading
  • Want a system to grade
    • program fragments
    • entire methods or combinations of methods
    • entire classes (or multiple classes)
  • Provide immediate feedback
    • decreases turnaround cycle
    • encourages exploration
an accessible system
An accessible system
  • Many students find the first several days in programming to be terrifying
    • new systems using different paradigms
    • programs that work differently
    • error messages that are undecipherable
    • have to write a lot of code just to get the simplest program
an accessible system6
An accessible system
  • Our system is designed to
    • remove the development environment
    • allow program fragments
    • provide immediate feedback
  • Our system is not designed to replace the professor
    • but it will grant the student greater and more timely feedback
provide appropriate feedback
Provide appropriate feedback
  • Compilers check syntax not semantics
  • Exceptions catch only gross errors
  • Unit testing allows very specific testing to home in on what is correct and isn’t correct
junit basics
JUnit basics
  • From www.junit.org
    • “JUnit is a simple framework to write repeatable tests.”
junit basics9
JUnit basics
  • As you write classes you write tests
    • for a LinkedList class
      • code to check for normal functioning of linked list
      • code to check exceptional circumstances
        • delete from empty, removing non-present element
junit architecture
JUnit architecture
  • tests are usually contained in separate class
    • LinkedList, LinkedListJUnit
  • JUnit will automatically run all methods that begin with test…
  • Test methods contain code to notify JUnit of failures
    • Failures may include not raising an exception
  • JUnit keeps track of success/failures
junit example
JUnit example
  • Imagine a Money class for keeping track of various international moneys
  • Constructor, add methods
junit test for money
JUnit test for Money

public class MoneyJUnit extends TestCase {

public void testSimpleAdd() {    

Money m12CHF= new Money(12, "CHF");

Money m14CHF= new Money(14, "CHF");     

Money expected= new Money(26, "CHF");     

Money result= m12CHF.add(m14CHF);     

assertTrue(expected.equals(result));

} }

common junit methods
Common JUnit methods
  • Assert.assertTrue(bool);
  • Assert.assertEquals(X , X);
  • Assert.assertNotNull(Object);
  • Assert.fail();
  • All have optional messages to attach.
handling exceptions
Handling exceptions

public void testThrowsException() {try { Money m = new Money(10,”XYZ”);

} catch (Exception IllegalTenderException ite) {

// do nothing, it was supposed to do this return;

}

Assert.fail(); // shouldn’t get here

}

  • Note uncaught exceptions fail by default.
junit and webwork
JUnit and WeBWorK
  • Have students type in a class/method/program fragment
  • Insert the code into a template designed by the problem creator
  • Compile the code, reporting errors if relevant
  • Use the standard testing mechanisms to measure relative correctness of code
writing junit problems
Writing JUnit problems
  • Write a template class
  • Write a JUnit class to test it
  • Write a WeBWorK problem
sample template class
public class ArraySort{

private int[] numList=

{12, 10, 8, 6, 4};

public ArraySort(){

sort();

print();

}

public void sort(){

replaceme

}

public void print(){

for(int i = 0; i<5; i++){

System.out.println( "" + numList[i]);

}

}

public int[] getArray(){

return numList;

}

public static void main( String [] args){

ArraySort ast = new ArraySort();

}

}

Sample template class
sample junit test
import junit.framework.*;

public class ArraySortJUnitTest extends TestCase

{

private int[] startArray = {12, 10, 8, 6, 4};

private ArraySort ast = new ArraySort();

private int[] endArray = ast.getArray();

public void testSlotOne(){

Assert.assertEquals(startArray[4],

endArray[0]);

}

public void testSlotTwo(){

Assert.assertEquals( startArray[3],

endArray[1]);

}

public void testSlotThree(){

Assert.assertEquals(startArray[2],

endArray[2]);

}

public void testSlotFour(){

Assert.assertEquals(startArray[1],endArray[3]);

}

public void testSlotFive(){

Assert.assertEquals(startArray[0],endArray[4]);

}

public static Test suite(){

return new TestSuite(ArraySortJUnitTest.class);

}

public static void main(String[] args){

ArraySortJUnitTest ajst = new ArraySortJUnitTest();

}

}

Sample JUnit test
system architecture
System Architecture
  • WeBWorK displays background info
  • User clicks on link which runs traditional Perl/CGI script
    • Displays exact question
    • Collects user input
system architecture 2
System Architecture (2)
  • On user input, X.java template expanded
  • Expanded X.java and XJUnit.java copied to unique temp directory
  • Code compiled, errors reported back to user
system architecture 3
System Architecture (3)
  • JUnit tests run on code
    • Code run inside strict Java sandbox
    • Not currently CPU Limited
  • Number of JUnit tests passed translated into score [0.0,1.0] (0.1 increments).
  • On user click, passed back to WeBWorK which records score.
sample junitwebwork problem
Sample JUnitWebWork problem
  • Currently involves copying lots of code to setup transfer between JUnit and CGI-Perl
    • Will be greatly simplified
  • Elements edited by problem writer
    • Problem description
    • Name of template class
next steps
Next steps
  • Writing problems
  • Cleaning/testing code
  • Improving interface with WeBWorK
    • Want to remove the extra clicks
    • Use WeBWorK 2.0
    • Provide Web interface for editing
  • Increasing security
    • Infinite loops still problem
    • Issues with doing file i/o