A boilerplate layout for CSE 205 console application assignments that allows for Windows users to easily automate test cases.
NOTE: You can delete the
.gitignore
file in thebin
,src
, andtest
directories. They are only included so that git will allow for these directories to be pushed, as empty directories are otherwise ignored.
NOTE: If you are running a UNIX-like system (macOS, WSL/Cygwin/MinGW, pretty much any Linux distro) you can use this version of the template here.
- Create a
src
folder, all.java
files will be placed here
- Create a
bin
folder, this folder will contain the compiled.class
file(s). - If your extensions are working correctly, you should observe this file be populated with the class files for your program automatically after configuring
settings.json
.
- Create a
test
folder and place all the given input an output text files in here - Your program's actual output will also be written to "myoutput" text files in this folder for comparison
- in the
test.ps1
file, paste this code:
$name = $args[0]
$numTests = $args[1]
for($i = 1; $i -le $numTests; $i++) {
if((Test-Path -Path test\input$i.txt -PathType Leaf) -and (Test-Path -Path test\output$i.txt -PathType Leaf)) {
Write-Output "Testing Case $i"
Get-Content test\input$i.txt | java -cp bin $name | Out-File -Encoding utf8 test\myoutput$i.txt
if(Compare-Object -CaseSensitive (Get-Content test\myoutput$i.txt) (Get-Content test\output$i.txt)) {
Write-Warning "Test Case $i Failed"
code --diff test\myoutput$i.txt test\output$i.txt
}
} else {
Write-Warning "Failed to locate files for Test Case $i, ensure both input$i.txt and output$i.txt are present in the test directory"
}
}
- If you don't already have a .vscode directory, create one.
- Create these two files if they don't exist already and set their contents to this:
settings.json
{
"java.project.sourcePaths": ["src"], // Source code
"java.project.outputPath": "bin" // Build output
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Tests",
"type": "shell",
"command": ".\\test.ps1 ${fileBasenameNoExtension} ${input:numTests}",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"inputs": [
{
"id": "numTests",
"type": "promptString",
"default": "4",
"description": "Number of test cases"
}
]
}