Tags » JUnit

Unit testing String Class's Immutability and StringBuilder Class's mutability.

String and StringBuilder are two popular java classes and both are meant for playing with strings of characters. And the major difference between them is String is immutable while StringBuilder is mutable. 266 more words

Junit

Selenium WebDriver Installation

The Selenium Web driver can be loaded and accessed directly in Java and other programing languages to build more a more comprehensive suite of tests. 143 more words

Selenium

Test log4j logging - add appender to root

Great article from slackhacker.com
http://slackhacker.com/2009/12/08/testing-logging-behaviour-in-four-code-lines-flat/

http://slackhacker.com/2012/04/16/testing-logging-behaviour-sans-mockito/

@Test
	public void testException {
		String customExceptionMessage = "Junit test exception";
		StringWriter stringWriter = new StringWriter();
		Appender appenderMock = new WriterAppender(new SimpleLayout(), stringWriter);
		Logger.getRootLogger().addAppender(appenderMock);
		
		try {
			Mockito.doThrow(new RuntimeException(customExceptionMessage)).when(testClass).doTestMethod(Mockito.any());
			/* run the test class*/
		} catch (Exception ex) {
			assertThat(ex.getMessage(), Is.is(customExceptionMessage));
		} finally {
			assertThat(stringWriter.toString(), StringContains.containsString(customExceptionMessage));
		}
		
		Logger.getRootLogger().removeAppender(appenderMock);
	}

Best Practices: Checking for Exceptions in JUnit Tests

Surround with try-catch block and include Assert.fail line

@Test
public void MissingScriptExpectException() {
try {
executeScriptRunner(userData, conditionData);
Assert.fail("This line should not be reached");
} catch (Exception ex) {
System.out.println("Caught! " + ex);
}
}

Java

Writing Test Automation Framework for Installers

Last few weeks I have spent considerable time writing integration test suite for one of our product installers. The goal of this test suite is to automatically test functionality of the product on various operating systems. 2,097 more words

Java

JUnit là gì?

Testing là vấn đề sống còn của software

Khi phát triển một sản phẩm phần mềm, testing là một công việc quan trọng. Nó đảm bảo rằng phần mềm khi ra đời có hoạt động như ban đầu đã định không? 391 more words

JUnit