Skip to content

Commit f7c8122

Browse files
committed
fix test runner
1 parent cda6367 commit f7c8122

File tree

2 files changed

+183
-35
lines changed

2 files changed

+183
-35
lines changed

_sources/overview.rst

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ jUnit Tests
13081308
public void testMain() throws IOException
13091309
{
13101310
// I wrote a method to run a method and send back the output - only works with String[] args for now
1311-
String output = getMethodOutput("StudentCode", "main");
1311+
String output = getMethodOutput("main");
13121312
String expect = "2\n3\n4\n5\n6\n7\n8\n9\n10\n";
13131313
13141314
assertEquals("Output doesn't match", cleanString(expect), cleanString(output));
@@ -1318,7 +1318,7 @@ jUnit Tests
13181318
@Test
13191319
public void testAdder() throws IOException {
13201320
StudentCode s = new StudentCode();
1321-
String msg = createMessage("Adding 2+2", ""+4, ""+s.adder(2,2));
1321+
String msg = "Adding 2+2" + ""+4 + ""+s.adder(2,2);
13221322
System.out.println("testing s.adder(2,2)");
13231323
assertEquals(msg, 4, s.adder(2,2));
13241324
assertEquals("adding 3+3", 6, s.adder(3,3));
@@ -1380,7 +1380,7 @@ jUnit Tests
13801380
public void testMain() throws IOException
13811381
{
13821382
// I wrote a method to run a method and send back the output - only works with String[] args for now
1383-
String output = getMethodOutput("StudentCode", "main");
1383+
String output = getMethodOutput("main");
13841384
String expect = "2\n3\n4\n5\n6\n7\n8\n9\n10\n";
13851385
13861386
assertEquals("Output doesn't match", cleanString(expect), cleanString (output));
@@ -1403,6 +1403,154 @@ jUnit Tests
14031403
}
14041404
}
14051405
1406+
.. activecode:: jUnitTesting3
1407+
:language: java
1408+
:autograde: unittest
1409+
1410+
In this project, you will create a class that can tell riddles like the following:
1411+
1412+
Riddle Question: Why did the chicken cross the playground?
1413+
Riddle Answer: To get to the other slide!
1414+
~~~~
1415+
public class Riddle
1416+
{
1417+
// 2 instance variables for Riddle's question and answer: private type variableName;
1418+
private String quest;
1419+
private String ans;
1420+
1421+
// constructor
1422+
public Riddle(String initQuestion, String initAnswer)
1423+
{
1424+
// set the instance variables to the init parameter variables
1425+
quest = initQuestion;
1426+
ans = initAnswer;
1427+
}
1428+
1429+
// Print riddle question
1430+
public void printQuestion()
1431+
{
1432+
// print out the riddle question with System.out.println
1433+
System.out.println(quest);
1434+
}
1435+
1436+
// Print riddle answer
1437+
public void printAnswer()
1438+
{
1439+
// print out the riddle answer with System.out.println
1440+
System.out.println(ans);
1441+
}
1442+
1443+
// main method for testing
1444+
public static void main(String[] args)
1445+
{
1446+
// call the constructor to create 3 new Riddle objects
1447+
1448+
// call their printQuestion() and printAnswer methods
1449+
1450+
}
1451+
}
1452+
====
1453+
//import codetesthelper.*;
1454+
1455+
// Test Code for Lesson 5.1.5 - Riddle
1456+
import static org.junit.Assert.*;
1457+
import org.junit.After;
1458+
import org.junit.Before;
1459+
import org.junit.Test;
1460+
1461+
import java.io.*;
1462+
1463+
public class RunestoneTests extends CodeTestHelper
1464+
{
1465+
public RunestoneTests()
1466+
{
1467+
super("Riddle"); // class name / location of main
1468+
1469+
Object[] values = new Object[]{"Question", "Answer"};
1470+
setDefaultValues(values);
1471+
}
1472+
1473+
@Test
1474+
public void testPrintQuestion()
1475+
{
1476+
String output = getMethodOutput("printQuestion");
1477+
String expect = "Question";
1478+
1479+
boolean passed = getResults(expect, output, "Checking method printQuestion()");
1480+
assertTrue(passed);
1481+
}
1482+
1483+
@Test
1484+
public void testPrintAnswer()
1485+
{
1486+
String output = getMethodOutput("printAnswer");
1487+
String expect = "Answer";
1488+
1489+
boolean passed = getResults(expect, output, "Checking method printAnswer()");
1490+
assertTrue(passed);
1491+
}
1492+
1493+
@Test
1494+
public void testDefaultConstructor()
1495+
{
1496+
String[] args = {"Question 1", "Answer 1"};
1497+
String output = checkDefaultConstructor();
1498+
String expect = "fail";
1499+
1500+
boolean passed = getResults(expect, output, "Checking default constructor");
1501+
assertTrue(passed);
1502+
}
1503+
1504+
@Test
1505+
public void testConstructor()
1506+
{
1507+
String[] args = {"Question 1", "Answer 1"};
1508+
String output = checkConstructor(args);
1509+
String expect = "pass";
1510+
1511+
boolean passed = getResults(expect, output, "Checking constructor with parameters");
1512+
assertTrue(passed);
1513+
}
1514+
1515+
@Test
1516+
public void testVariableTypes()
1517+
{
1518+
String varTypes = "String String";
1519+
String output = testInstanceVariableTypes(varTypes.split(" "));
1520+
1521+
boolean passed = getResults(varTypes, output, "Checking Instance Variable Type(s)");
1522+
assertTrue(passed);
1523+
}
1524+
1525+
@Test
1526+
public void testPrivateVariables()
1527+
{
1528+
String expect = "2 Private";
1529+
String output = testPrivateInstanceVariables();
1530+
1531+
boolean passed = getResults(expect, output, "Checking Private Instance Variable(s)");
1532+
assertTrue(passed);
1533+
}
1534+
1535+
1536+
@Test
1537+
public void testMain()
1538+
{
1539+
String output = getMethodOutput("main");
1540+
1541+
String expect = "6 line(s) of text";
1542+
String actual = " line(s) of text";
1543+
1544+
if (output.length() > 0) {
1545+
actual = output.split("\n").length + actual;
1546+
} else {
1547+
actual = output.length() + actual;
1548+
}
1549+
boolean passed = getResults(expect, actual, "Checking main method");
1550+
assertTrue(passed);
1551+
}
1552+
}
1553+
14061554
Catch2 C++ Unit Tests
14071555
---------------------
14081556

pavement.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import paver
22
from paver.easy import *
33
import paver.setuputils
4+
45
paver.setuputils.install_distutils_tasks()
56
import os, sys
67
from socket import gethostname
@@ -12,46 +13,45 @@
1213
project_name = "overview"
1314
###############################
1415

15-
master_url = 'https://runestone.academy'
16+
master_url = "https://runestone.academy"
1617
if master_url is None:
17-
if gethostname() in ['runestone.academy', 'runestone-deploy', 'rsbuilder']:
18-
master_url = 'https://runestone.academy'
19-
elif 'RUNESTONE_HOST' in os.environ:
20-
master_url = "http://{}".format(os.environ['RUNESTONE_HOST'])
18+
if gethostname() in ["runestone.academy", "runestone-deploy", "rsbuilder"]:
19+
master_url = "https://runestone.academy"
20+
elif "RUNESTONE_HOST" in os.environ:
21+
master_url = "http://{}".format(os.environ["RUNESTONE_HOST"])
2122
else:
22-
master_url = 'http://127.0.0.1:8000'
23-
24-
master_app = 'runestone'
25-
serving_dir = "./build/"+project_name
26-
dest = './published'
23+
master_url = "http://127.0.0.1:8000"
2724

28-
options(
29-
sphinx = Bunch(docroot=".",),
25+
master_app = "runestone"
26+
serving_dir = "./build/" + project_name
27+
dest = "./published"
3028

31-
build = Bunch(
32-
builddir="./build/"+project_name,
29+
options(
30+
sphinx=Bunch(docroot=".",),
31+
build=Bunch(
32+
builddir="./build/" + project_name,
3333
sourcedir="_sources",
34-
outdir="./build/"+project_name,
34+
outdir="./build/" + project_name,
3535
confdir=".",
36-
project_name = project_name,
37-
template_args = {
38-
'course_id':project_name,
39-
'login_required':'false',
40-
'appname':master_app,
41-
'loglevel':10,
42-
'course_url':master_url,
43-
'dynamic_pages': True,
44-
'use_services': True,
45-
'basecourse': 'overview',
46-
'python3': 'true',
47-
'downloads_enabled': 'true',
48-
'allow_pairs': 'false',
49-
'enable_chatcodes': 'false'
50-
}
51-
)
36+
project_name=project_name,
37+
template_args={
38+
"course_id": project_name,
39+
"login_required": "false",
40+
"appname": master_app,
41+
"loglevel": 10,
42+
"course_url": master_url,
43+
"dynamic_pages": True,
44+
"use_services": "true",
45+
"basecourse": "overview",
46+
"python3": "true",
47+
"downloads_enabled": "true",
48+
"allow_pairs": "false",
49+
"enable_chatcodes": "false",
50+
},
51+
),
5252
)
5353

5454
version = pkg_resources.require("runestone")[0].version
55-
options.build.template_args['runestone_version'] = version
55+
options.build.template_args["runestone_version"] = version
5656

5757
from runestone import build # build is called implicitly by the paver driver.

0 commit comments

Comments
 (0)