怀孕不能吃什么药| r一谷氨酰转移酶高说明什么| 发热出汗是什么原因| 疤痕修复用什么药膏好| 吃白糖有什么好处和坏处| secret是什么意思| 1979年出生属什么生肖| 奚字五行属什么| 向日葵什么时候成熟| 七宗罪都是什么| 为什么老放屁| 隔离霜和粉底液有什么区别| 为什么长痣越来越多了| 人生只剩归途什么意思| 轻度郁症有什么表现| yonex是什么品牌| 晏字五行属什么| 猪和什么属相不合| 什么是亚麻籽| 梅毒是什么症状图片| 神经内科主要看什么病| 孕妇多吃什么水果比较好| 脑ct都能查出什么病| 发烧应该吃什么药| 潜力是什么意思| 怀孕做糖耐是检查什么| 定量是什么意思| 肺结核复发有什么症状| PPm什么意思| 羊水多了对宝宝有什么影响| 人身体缺钾是什么症状| 灰菜有什么功效与作用| 什么颜色加什么颜色等于黑色| 鹿吃什么| jw是什么意思| 小儿手足口病吃什么药| 吃什么祛痰化痰最有效| chemical是什么意思| 萎缩性阴道炎用什么药| 双向情感障碍症是什么病| female什么意思| 对口升学什么意思| 宝宝囟门什么时候闭合| 帝陀表什么档次| 梦见放生鱼是什么意思| 胸有成竹是什么意思| 医学P代表什么| 胃疼喝什么粥| 心肌病是什么病严重吗| 经期便秘是什么原因| ot是什么| 发烧呕吐吃什么药| 百香果有什么好处| 苛捐杂税是什么生肖| 虢是什么意思| 尿酸高说明什么问题| 2010年什么年| 六月属什么生肖| 草鱼又叫什么鱼| 睡醒口干舌燥是什么原因| 艾司唑仑是什么药| 掷是什么意思| 生理期提前是什么原因| 佩戴朱砂有什么好处| 惊天动地是什么生肖| 飞蚊症是什么原因引起的| 小孩便秘吃什么食物好| 什么的亮光| 水泡长什么样| 属猴和什么属相最配| 背上长白斑是什么病的症状| 头晕是什么引起的| 副主任医师什么级别| 特效药是什么意思| 发光免疫是检查什么的| 细菌性痢疾症状是什么| 盆腔炎用什么药效果好| 梅毒是什么| 华侨是什么| 淋巴结肿大是什么引起的| 肝胆相照什么意思| 细菌感染引起的发烧吃什么药| 白带有腥味是什么原因| 俄狄浦斯情结是什么意思| 十二月十二日是什么星座| 甘油三酯高吃什么药| 张姓为什么出不了皇帝| 什么茶最好| 胸口正中间疼痛是什么病症| 儿童过敏性结膜炎用什么眼药水| 谨记教诲是什么意思| 什么叫阳性| 核桃壳有什么用| 冷暖自知上一句是什么| mr平扫是什么检查| 切洋葱为什么会流泪| cts是什么意思| 吃什么食物能降低胆固醇| 闪卡是什么意思| 西红柿不能和什么一起吃| 肚胀是什么原因| lena是什么意思| 2.22是什么星座| 巫师是什么意思| 乙肝五项135阳性是什么意思| 有何特长一般填什么好| 西游记主题曲叫什么| 熬中药用什么锅| 粉碎性骨折是什么意思| 月子吃什么最下奶| 等不到天黑烟火不会太完美什么歌| 肝肾亏虚吃什么药| 磨砂皮是什么皮| 盐酸安罗替尼胶囊主要治疗什么| 两个月小猫吃什么食物| 白发多吃什么可以改善| 转隶是什么意思| 离婚要什么手续和证件| 青霉素过敏可以吃什么消炎药| 呆小症是缺乏什么激素| 其他垃圾有什么| 9月28日什么星座| 海参什么时间吃最好| 红红的苹果像什么句子| 来例假吃什么好| 股长是什么职位| 什么飞什么跳| 儿童抽动症挂什么科| 金刚菩提是什么植物的种子| 负利率是什么意思| 赤色是什么颜色| 广东省省长是什么级别| 黄茶适合什么人喝| 什么的变化| 男士带什么手串好| 花生属于什么类食物| 偷鸡不成蚀把米是什么意思| 女性绝经期在什么年龄是正常的| 菠菜和豆腐为什么不能一起吃| 来苏水又叫什么名字| 瓜子脸适合剪什么刘海| 龙是什么意思| 什么是慢阻肺| exo的e为什么不发音| 什么什么为难| 外婆菜是什么菜| 女内分泌检查什么项目| 规培生是什么意思| 杨过是什么生肖| 什么样的人不适合吃人参| 一心一意什么意思| 为什么会骨盆前倾| 银杏是什么| 独在异乡为异客异是什么意思| 肾囊肿用什么药| 阿q精神是什么意思| 血热是什么意思| 拉肚子能吃什么菜| 月经期间同房有什么危害| 438是什么意思| 梦到鞋子是什么意思| 2月21日什么星座| 焦俊艳和焦恩俊是什么关系| 李子有什么营养| 奶酪和芝士有什么区别| 下巴长痘什么原因| 1983是什么年| 五灵脂是什么东西| fsa是什么意思| 性是什么意思| 神经疼吃什么药| dd什么意思| 1.17是什么星座| 早上7点是什么时辰| 奇异果和猕猴桃有什么区别| 葱长什么样| 肠胃炎不能吃什么| 为什么冬吃萝卜夏吃姜| 手术后吃什么鱼伤口愈合快| 入伏吃什么| 3.5是什么星座| 得性病有什么症状| 理性是什么意思| 心梗挂什么科| 03年是什么年| 手总是发麻是什么原因| 踩雷是什么意思| 黄精长什么样| 手淫会导致什么疾病| 吃土豆有什么好处和坏处| 喝椰子汁有什么好处| 长期胃胀是什么原因| 中暑吃什么药好得快| 产前筛查是检查什么| 产后复查挂什么科| 欲盖弥彰什么意思| 慢阻肺是什么原因引起的| 人发胖的原因是什么引起的| 脚踝肿了是什么原因| 心血虚吃什么中成药| 什么是肺腺瘤| 肚子疼做什么检查| 梦见自己和别人吵架是什么意思| 早晨起床口干口苦是什么原因| 能力是什么| sga是什么意思| 舌头辣辣的是什么原因| 阴道发臭是什么原因| 来大姨妈吃什么水果好| 身上长很多痣是什么原因| 灌肤是什么意思| fierce是什么意思| 院子里有蛇是什么征兆| 雨云是什么字| 肺结节有什么症状| whan是什么意思| 病毒由什么构成| 含羞草长什么样| 康庄大道什么意思| 鑫字属于五行属什么| 好马不吃回头草是什么意思| 扁导体发炎吃什么药| 什么原因引起血糖高| 血糖低会出现什么症状| 吃毓婷有什么副作用| 为什么最近一直下雨| 狗感冒了吃什么药| 觅食是什么意思| 吃芒果过敏吃什么药| 佛龛是什么| 曹操属什么生肖| 牙龈肿痛用什么药| 什么鸟不能吃| 不什么其什么| 周二右眼皮跳是什么预兆| 肠镜活检意味着什么| 糖尿病患者可以吃什么水果| 查乙肝挂什么科| 梦见买帽子是什么意思| 李自成为什么会失败| 亏空是什么意思| 老虎菜是什么菜| 低度鳞状上皮内病变是什么意思| jk是什么意思| 轮状病毒吃什么药| 念珠菌阳性是什么病| 内热外寒感冒用什么药| 腺肌症有什么症状表现| 有什么好处| 病毒是什么生物| 水猴子是什么| 护士还能从事什么工作| 三峡大坝什么时候建成的| 吃什么减脂肪最快最有效的方法| 头昏脑胀是什么原因| 交工是什么意思| 樱桃有什么营养| 在野是什么意思| 香水前调中调后调是什么意思| 什么花是紫色的| 造影是检查什么| 荔枝为什么上火| 猪横利是什么| PPm什么意思| 百度
DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Attention Kubernetes users! DZone is researching how K8s usage is evolving in 2025 — tell us the good, the bad, + the frustrating.

Getting Started With DevSecOps: This Refcard provides actionable insights for embedding security into your DevOps culture and workflows.

Data Engineering: Not your average "AI is changing everything" report. Dive into tooling, strategy, + systems in scalable data ecosystems.

Java Caching: This Refcard explores core caching concepts and demonstrates how to implement them using Java’s JCache API.

Related

  • Micronaut With Relation Database and...Tests
  • Java CI/CD: From Local Build to Jenkins Continuous Integration
  • A Systematic Approach for Java Software Upgrades
  • Integrate Cucumber in Playwright With Java

Trending

  • Data Partitioning and Bucketing: How Modern Data Systems Organize and Optimize Your Data
  • Secure Microservices in Java: Cloud-Native Design With Zero Trust Architecture
  • Squid Game: The Clean Code Trials — A Java Developer's Survival Story
  • Bring Your Own Feed (BYOF): An Engineer's Guide to Effective Threat Intelligence
  1. DZone
  2. Coding
  3. Java
  4. Testing Java EE (or Why Integration Tests Are Overrated)

中国商务部组织贸易促进团赴印度开展经贸交流活动

Testing that goes beyond just unit testing and integration testing. Why we should be doing full system testing.

By 
Sebastian Daschner user avatar
Sebastian Daschner
·
Apr. 27, 16 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
25.8K Views
百度 据此,北京知识产权法院认为争议商标与引证商标不构成使用在同一种或类似商品上的近似商标,据此一审判决撤销商评委所作复审决定,并判令商评委重新作出决定。

Join the DZone community and get the full member experience.

Join For Free

In (enterprise) development testing often is treated very much as poor relations. But for more than “Hello World” applications testing is not just nice to have (at the end of the project) rather than crucial for working software. How to test Java EE applications in a productive yet comprehensive way?

A good test has following criteria: It must be fast, reliable and easy to write and maintain.

There are several ranges of testing like unit, integration or system tests. The smaller the scope of the test is the easier it is to write and to maintain, the faster it runs but also the more “far away” it is from the real world application.

IMO following test scopes should be applied in certain situations.

Unit Tests

Unit tests cover the business logic of a single component?—?usually a class?—?and provide very fast feedback for the developers without needing to startup any container.

The simplest way to unit test Java EE components is to use plain JUnit without any special runner and Mockito to mock away every other involved component.

@Stateless 
public class TaskStore { 

  @PersistenceContext 
  EntityManager entityManager; 

  public List<Task> listAll() { 
    return entityManager.createNamedQuery("Task.findAll", Task.class).getResultList(); 
  } 

  public List<Task> filterAll(final Filter filter) { 
    return listAll().parallelStream().filter(filter::matches).collect(Collectors.toList()); 
  } 

  ... 
}


import static org.mockito.Matchers.*; 
import static org.mockito.Mockito.*; 

public class TaskStoreTest { 
  private TaskStore cut; 

  @Before 
  public void setUp() { 
    cut = new TaskStore(); 
    cut.entityManager = mock(EntityManager.class); 

    TypedQuery mockQuery = mock(TypedQuery.class); 
    when(cut.entityManager.createNamedQuery(anyString(), any())).thenReturn(mockQuery); 
    when(mockQuery.getResultList()).thenReturn(sampleTasks()); 
  } 

  @Test 
  public void testFilterContextMatch() { 
    Filter filter = new Filter(); 
    ... 

    List<Task> filteredTasks = cut.filterAll(filter); 
    assertEquals(1, filteredTasks.size()); assertEquals(...); 
    verify(cut.entityManager).createNamedQuery("Task.findAll", Task.class); 
  } 
}


As EJBs and CDI managed beans are basically POJOs with annotations, it’s trivial to create or mock them in a test.

@Injected dependencies can be mocked and manually modified in the class due to the fact that the test resides in the same package as the component and can access the package-private defined property. Not all developers may agree to making the properties not private just for testability. However, this enables the test to easily modify the dependencies without the need for (slow) Reflection. And the Java EE implementation will prevent production code to reset the dependencies of any managed bean.

With that approach one can run hundreds of tests in no time. Any special @RunWith runner definition should be considered over-engineering for a simple unit test?—?with the exception of Parameterized tests. The latter are in fact very helpful for mass tests.

In general: You can be creative in how to write tests, but they must run fast and simplicity wins.

Integration Tests

Integration tests in a Java EE environment usually mean to combine a few components in a sort of emulated container. Test frameworks like Arquillian can be used to accomplish this.

The problem with this approach is that it consumes much more time than a unit test as the container has to be started every time. That is why it can be a problem to cover business logic with integration tests.

The killer use case however is to test CDI extensions and technical Java EE “plumbing”?—?rather than business logic. Testing custom CDI producers or custom scopes for example is a perfect scenario. But: These tests should be the big exception in your application.

System Tests

Unit and integration tests are nice to get a fast feedback but if your application is solely tested by them you’ll get other errors on production (like environment-specific configuration, problems with the server environments or external interfaces, etc.). A full system test on the other hand covers all business use cases end-to-end. The application should run in the same way during the test as it would in production. That means the system test environment is ideally the same?—?including server configuration, databases, network, etc.?—?with the only difference that it’s not the real production server. During the tests all external systems are mocked away and ensure that the application communicates with them in a correct way.

Having that said means also that integration tests which combine a few components are somewhat overrated. Your application can’t rely on integration tests only and then the feedback time saved is in general not worth the overhead of writing and maintaining them.

That is why I recommend to only have simple unit tests for fast feedback and fully-fledged system tests?—?with the exception that integration tests sometimes help to test Java EE “plumbing”.

An easy way to achieve an identical system for all environments is to use containers. The container which incorporates the application, the application server and the operating system is built once from the CI server and used for all environments. Using this approach highly increases the stability as exactly the same artefacts run in production which have been tested extensively.

Conclusion

From my point of view a productive and yet comprehensive Java EE testing pipeline looks like follows:

  • Unit tests with plain JUnit (no @RunWiths needed)
  • Integration tests for business logic considered harmful
  • Full system tests which cover all business use cases
  • Continuous Deployment pipeline deploying and starting the system tests automatically
  • Automated performance / stress tests depending on the requirements
  • Deploying the tested application (ideally as container) in production


unit test Java EE Integration Java (programming language) operating system application

Published at DZone with permission of Sebastian Daschner. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Micronaut With Relation Database and...Tests
  • Java CI/CD: From Local Build to Jenkins Continuous Integration
  • A Systematic Approach for Java Software Upgrades
  • Integrate Cucumber in Playwright With Java

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

maxrieny是什么品牌 刘三姐是什么生肖 恒心是什么意思 手电筒的金属外壳相当于电路中的什么 为什么说成也萧何败也萧何
人的舌头有什么作用 无创是什么 炖汤用什么鸡 爸爸的爷爷叫什么 盆腔炎用什么药效果好
胸闷气短吃什么药 尿带血什么原因 壬水代表什么 打呼噜是什么原因引起的 仕字五行属什么
桃子跟什么不能一起吃 塑化剂是什么 海南属于什么气候 cm3是什么单位 什么是钾肥
苦杏仁味是什么中毒hcv9jop0ns8r.cn 脆皖鱼是什么鱼adwl56.com 猪心炖什么适合孩子hcv8jop6ns2r.cn 卢森堡为什么那么有钱bfb118.com 脸色发黑是什么病的前兆xscnpatent.com
弧度是什么意思hcv8jop0ns9r.cn 结婚20年是什么婚姻hcv8jop1ns9r.cn 为什么会有痛经hcv8jop4ns3r.cn 奥林匹克精神是什么hcv7jop9ns2r.cn 艾灸有什么好处hcv8jop4ns1r.cn
生普洱和熟普洱有什么区别hcv8jop0ns1r.cn 肺肿了是什么病严重吗hcv8jop8ns7r.cn 贾赦和贾政是什么关系tiangongnft.com 攀龙附凤是什么生肖hcv9jop4ns8r.cn 内痔吃什么药bfb118.com
吃什么容易发胖hcv9jop1ns0r.cn 郭五行属什么hcv8jop3ns3r.cn 中产家庭的标准是什么hcv7jop4ns5r.cn 疱疹不能吃什么hcv8jop4ns0r.cn 心电图窦性心动过缓是什么意思qingzhougame.com
百度