Commits

Micha Kops committed 4165104 Draft

Examples for test execution order and temporary folder handling added.

Comments (0)

Files changed (5)

 .project
 .settings
 .classpath
-.target
+.target
+infinitest.filters

src/test/java/com/hascode/tutorial/ExecutionOrder1Test.java

+package com.hascode.tutorial;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class ExecutionOrder1Test {
+
+	@Test
+	public void bTest() {
+		System.out.println("b");
+	}
+
+	@Test
+	public void aTest() {
+		System.out.println("a");
+	}
+
+	@Test
+	public void dTest() {
+		System.out.println("d");
+	}
+
+	@Test
+	public void cTest() {
+		System.out.println("c");
+	}
+}

src/test/java/com/hascode/tutorial/ExecutionOrder2.java

+package com.hascode.tutorial;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ExecutionOrder2 {
+
+	@Test
+	public void bTest() {
+		System.out.println("b");
+	}
+
+	@Test
+	public void aTest() {
+		System.out.println("a");
+	}
+
+	@Test
+	public void dTest() {
+		System.out.println("d");
+	}
+
+	@Test
+	public void cTest() {
+		System.out.println("c");
+	}
+}

src/test/java/com/hascode/tutorial/ParameterizedTest.java

 	private final Long idParam;
 	private final User userParam;
 
-	public ParameterizedTest(final Long id, final User user) {
-		this.idParam = id;
-		this.userParam = user;
+	public ParameterizedTest(final Long idParam, final User userParam) {
+		this.idParam = idParam;
+		this.userParam = userParam;
 	}
 
 	@Test
 	public void testUserMapping() {
 		UserDao userDao = new UserDao();
 		User user = userDao.findById(idParam);
+		System.err.print(idParam + " :\t");
+		System.err.println(userParam.toString());
 		assertEquals(idParam, user.getId());
 		assertEquals(userParam.getName(), user.getName());
 	}

src/test/java/com/hascode/tutorial/TemporaryFolderTest.java

+package com.hascode.tutorial;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class TemporaryFolderTest {
+	File parentFolder = new File("/tmp");
+
+	@Rule
+	public TemporaryFolder folder = new TemporaryFolder(parentFolder);
+
+	@Test
+	public void testUsingTempFolder() throws IOException {
+		File newFile = folder.newFile("testfile.txt");
+		File subDir = folder.newFolder("subfolder");
+		File someFile = new File(subDir, "test.txt");
+		someFile.createNewFile();
+		assertTrue(someFile.exists());
+		assertTrue(newFile.exists());
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.