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


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


Test log4j logging - add appender to root

Great article from slackhacker.com


	public void testException {
		String customExceptionMessage = "Junit test exception";
		StringWriter stringWriter = new StringWriter();
		Appender appenderMock = new WriterAppender(new SimpleLayout(), stringWriter);
		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));

Best Practices: Checking for Exceptions in JUnit Tests

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

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


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


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