Skip to content

Latest commit

 

History

History
125 lines (87 loc) · 3.84 KB

README.md

File metadata and controls

125 lines (87 loc) · 3.84 KB

README

This project is not actively maintained!

Clone this repo:

git clone git://github.com/Weltraumschaf/cacert-frontendtests.git

Next steps to get started

  1. Install Apache Maven

    • Debian Linux:

      $ sudo apt-get install maven2

    • Windows: [TBD]

    • Mac OS X: Maven is already installed.

  2. Install Sun Java JRE and JDK

    • Debian Linux:

      $ sudo apt-get install sun-java6-jre sun-java6-jdk

    • Windows: [TBD]

    • Mac OS X: Maven is already installed.

  3. Build the project (Make sure, you're in the project root directory, where the pom.xml file is located)

     $ mvn test
    

Maven will download all needed dependencies declared in the pom.xml file, build the project and execute all present unittests. If all went okay maven will terminate with the message

[INFO] BUILD SUCCESSFUL

and some runtime statistics.

Project Setup in your IDE

Netbeans

Recommended IDE for developing frontend tests is NetBeans because you just need to open the pom.xml and nothing else. With Eclipse the use of Maven is a bit more hassle. For getting the JavaDoc and sources of the dependeny open the project explorer in Netbeans and right click on the folder Dependencies and just clock the apropriate menue items.

Eclispe

[TBD]

How to write a test

In the project view (in Netbeans) you will see the directoy 'Source Packages' and 'Test Packages'. In the first one you will only find helper classes (e.g. for loading personas, create fixtures etc.). In the latter one you will find the the unit test classes (either for the helper classes or the frontent tests). As unit test framework JUnit is used. The frontent tests itself are contained in the package org.cacert.frontendtests. In this package you will add your tests. If you're not familiar with packages in Java read this.

Writing a test with JUnit follows nearly the same rules as in PHPUnit (because PHPUnit is a JUnit clone). You also need to extend a base class. But you will not extend the JUnits default TestCase but AbstractTestCase from the package org.cacert.frontendtests. This class provides helper methods for creating Webdriver instances, personas, fixtures or logged in sessions.

Some Java hints:

  • Attend the @Override annotation, if you overwrite a method. If you ommit this a compiler warning will be thrown.
  • No function keyword is needed for a method declaration, but a return type is required.
  • You can ommit this inside your scope, but keep in mind that local variables will shadow class fields.
  • Strings are double quoted "string", single quotes are characters 'c'!
  • Annotations are something similar to interfaces and so need to be imported.

An example for a test:

package org.cacert.frontendtests;

import org.junit.Ignore;

// You do not need to import AbstractTestCase because
// you are in the same package!

public class MyFirstTest extends AbstractTestCase {

	@Override
	protected void setUp() {
		// setup stuff
	}

	@Override
	protected void tearDown() {
		// teardown stuff
	}

	@Ignore("Not ready yet")
	public void testSomething() {
		// your test code goes here
	}
}

Some nice examples about annotations just found here.