Tag Archives: Test

The if statement in a JSP WITH JSTL



Introduction

The JavaServer Pages Standard Tag Library (JSTL) allows you to use functional tags which simplify  programming in JSP’s. This example shows how it’s done with a simple test for a condition

<%-- Declare the core library --%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>

<%-- Simple  conditions --%>
<c: test='${param.p == "someValue"}'>
    Generate this template text  p equals someValue
</c:>

<c: test='${param.p}'>
    Generate this template text  p equals "true"
</c:>

Reference:

Testing in Java

Introduction

In the Java Programming language we use a discipline for testing called Test Driven Development (TDD). It’s the way we Develop Java Applications. Before we actually start writing code we first create a JUnit test case. This is just our functional code but enhanced with assertions that makes sure that the code will work as expected.

JUnit
JUnit

This may seem overkill but actually it’s a big timesaver because it’s automated. Once we  know what our class should do we start coding it as a Test Case. In order to enable this, we add the Junit Jar in our Classpath and start coding.

Real world advantages

Everyone who ever did Application Support will understand the advantages. When something is wrong and you’re job is to figure out what it is you definitely profit from knowing which parts of the Application are definitely good and can be excluded from testing manually. Also deployment is much easier and more professional when you can deliver the project together with a professional looking test report.

Building Projects

After the Java development is done we extract the functional code and start working on the build script. This can either be done with Apache Ant or Apache Maven. The latter has the advantage of being dependancy aware, which is a big advantage because it will automatically download the required dependancies during the building process.

In the building scripts (whichever we use, the Junit tests are all included and executed during building. With every build a nice looking test report is generated which shows us if everything is still working as expected.

Continuous Integration

For big projects which are continuously updated there is Continuous integration. The project is buid over and over again. This is done by a Web Application which resides on a Servlet Container or Web Application Server. The Web Application is usually Apache Jenkins. It’s widely used in the larger Open Source projects. You can see Jenkins in action at https://builds.apache.org/. Open the link and choose a project. You can also choose to monitor the projects life.

Conclusion

Java Junit testing makes it easier for Java Developers to produce high quality and stable code. It also saves time and efforts.