Testing in Java

QA is important for production. Testing is important for QA. 

Here I would like to talk about testing in Java application development. It won't refer to project process/life cycle control,  I will only talk something about automatically unit testing.

 

Test Data Design and Populate

There are always DB interaction in a Java enterprise application, in order to make sure persistence layer and business layer work well, we need to design test data.

Even in some pure java tools application, we need to design some test data to test extrime use cases.

 

You can use DBUnit or JDBC to populate and clean your test data aournd/after/during test case running. 

 

Test Case Design

System Test: Business Use Case Test

We can say test case design does really depend on your businesses use cases.  In fact, it is not enough, sometime and always, business use cases testing will always come in stage of  "Integration Test"/"System Test"/"End2End Test".

 

Unit Test

There are always JUnit test for:

  • A line of java function code
  • All blocks in a method
  • All methods in a java class
  • Interaction between java classes
  • Java classes security and instances in JVM

They are always come during development. 

 

Test Requirement birth xUnit

As I will list in this chapter, sometime how you want to test your code and which information will be used to assert valid will push you to define or find some useful tools to help your test design.

How to test private method?

Some people use "protected" keywords to replace "private".  I do not think it is a good design. If we want to define some unit test for private methods, it is better to design "white box" test cases for public functions which will invoke private functions.

Unit Test for Servlet

HttpUnit provide ServletRunner to simulate Servlet Container to test servlet without Java application server running.

Unit Test for Spring

We can use SpeingJUnit4ClassRunner to test Spring in standalone JVM.

Unit Test for EJB

There should be a EJB container to test your EJB functions. Normally you have to design your EJB client as test cases and deploy your EJB application in EJB container.

 

Unit Test for XML

Here I would like to list a third party tool: xmlunit which can be used to check XML content. For example, we can use xmlunit to compare if two XML contents same or not. 

UI Automatic Test

Most of Java Enterprise application provide user interfaces, so normally we can design some automatically test case on user interface:

 

  • Simulator user manipulate actions in GUI: input data, click some button.
  • Check expected item in UI

 

Httpunit and vmaggie (to be updated) is used in my current project for GUI automatic testing.  How to select UI automatically test tools: 1) which language for developing; 2) how the tool execution a test and if it satisfies your UI implementation...

 

Performance Test

Performance test is importance, you can enhance your prouction quality in stress testing, safety testing and you can also get bench mark to define the optimze configuraton parameters.

 

Normally performance test cases will focus on a business use case.  The test environement: hardware and software should be coherent with deployment ENV.

 

There are two kinds performance test:

 

  1. Automatically performance test: using tools Jmeter or LoadRunner to test some use case and it can be intergrated with automatically build.
  2. Some mannually bench mark test: optimize functiona or define benchmark for configurations. It can also use some tools in automaticaly test to prepare test data and launch testing.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值