$ export CLASS_HOME=$HOME/proj/784 $ export PROJECT_BASEDIR=$CLASS_HOME/exercises/ex1 $ mkdir -p $PROJECT_BASEDIR
$PROJECT_BASEDIR
+---/src/main/java/myorg/mypackage/ex1
+---/src/test/java/myorg/mypackage/ex1
+---/target/classes
+---/target/test-classes
+---/target/test-reportspackage myorg.mypackage.ex1;
public class App {
public int returnOne() {
System.out.println( "Here's One!" );
return 1;
}
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}package myorg.mypackage.ex1;
import static org.junit.Assert.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest {
private static Log log = LogFactory.getLog(AppTest.class);
@Test
public void testApp() {
System.out.println("testApp");
App app = new App();
assertTrue("app didn't return 1", app.returnOne() == 1);
}
}> javac src/main/java/myorg/mypackage/ex1/App.java -d target/classes > jar cvf target/ex1.jar -C target/classes . added manifest adding: myorg/(in = 0) (out= 0)(stored 0%) adding: myorg/mypackage/(in = 0) (out= 0)(stored 0%) adding: myorg/mypackage/ex1/(in = 0) (out= 0)(stored 0%) adding: myorg/mypackage/ex1/App.class(in = 519) (out= 350)(deflated 32%) > jar tf target/ex1.jar META-INF/ META-INF/MANIFEST.MF myorg/ myorg/mypackage/ myorg/mypackage/ex1/ myorg/mypackage/ex1/App.class
> export JUNIT_JAR=`cygpath --windows c:/jhu/repository/junit/junit/4.10/junit-4.10.jar
> javac -classpath "target/ex1.jar;$JUNIT_JAR" \
src/test/java/myorg/mypackage/ex1/AppTest.java -d target/test-classes
target/
+---classes/myorg/mypackage/ex1/App.class
+---test-classes/myorg/mypackage/ex1/AppTest.class
+---test-reports
+---ex1.jar> java -classpath "target/ex1.jar;$JUNIT_JAR;target/test-classes" \ org.junit.runner.JUnitCore myorg.mypackage.ex1.AppTest .testApp Here's One! Time: 0.013 OK (1 test)
//AppTest.java
@Test
public void testFail() {
System.out.println("testFail");
App app = new App();
assertTrue("app didn't return 0", app.returnOne() == 0);
}
.testApp
Here's One!
.testFail
Here's One!
F
Time: 0.015
There was 1 failure:
1) testFail(myorg.mypackage.ex1.AppTest)junit.framework.AssertionFailedError: app didn't return 0
at myorg.mypackage.ex1.AppTest.testFail(AppTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
FAILURES!!!
Tests run: 2, Failures: 1, Errors: 0In this part of the exercise you setup, built, and tested a sample project with only command-line commands. You did this to help show what higher level tools will need to do as well. Even though the command line provides clarity, it doesn't scale and shell scripts aren't generally portable and optimized (wrong tool for the job). Hopefully, after going through this, you have an understanding of the low level structure and usecases and are now interested adding a build environment.