Last week, ours teacher taught us 'Software Delivery and Build Management'. And in this class, our teachers gave us a task about Develop the project “HelloWorld” and Install Maven and Build the “HelloWorld” Project. So I want to write something about using Maven and Junit.
1.Download Maven and configure environment variables
MAVEN_HOME: D:\apache-maven-3.3.1-bin\apache-maven-3.3.1
MAVEN: %MAVEN_HOME%\bin
PATH:%MAVEN%;
Then use cmd command 'mvn -v' to check the environment variables.
2.Using maven create your own project
After running this command, you will find that in the directory of C:/user/Anonymous, you have created your own project.
my-app-simple
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mycompany
| `-- app
| `-- App.java
`-- test
`-- java
`-- com
`-- mycompany
`-- app
`-- AppTest.java
3.Compile, test and package
This is compile command.
This is test command.
This is package command.
4.Import your project into Eclipse
Window->Preferences->Maven->Installations
Then add your maven into the Eclipse.
Import->Others->Maven->Existing Maven Projects
5.Download Junit and configure it
6.Write your own project code and test code
In App.java
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
{
public String sayApp() {
return "Hello Wudi!";
}
public static void main( String[] args )
{
App app = new App();
System.out.println( "Hello Wudi!" );
}
}
In AppTest.java
package com.mycompany.app;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
App app = new com.mycompany.app.App();
assertEquals("Hello Wudi!", app.sayApp() );
}
}
Then you can run your project and get what you want.
That's all.
To be professional.