简体   繁体   English

Java:在编译时或在应用程序执行时运行测试

[英]Java: running test at compilation time or at application execution

First of all I am not good at testing. 首先我不擅长测试。 I have an OSGI CRUD application. 我有一个OSGI CRUD应用程序。 And I want to make tests for auto testing business logic. 我想对自动测试业务逻辑进行测试。 And I see here two options: 我在这里看到两个选择:

  1. run tests at compilation time - at certain maven phase 在编译时运行测试-在某些Maven阶段
  2. make tests as separate bundle and run it after starting the application. 作为单独的捆绑软件进行测试,然后在启动应用程序后运行它。 For example, if I click somewhere at main menu. 例如,如果我单击主菜单上的某个位置。

Which one is the right choice? 哪个是正确的选择? Or both are possible? 还是两者都有可能?

The reasons why I am asking this questions are the following: 我问这个问题的原因如下:

  1. I've never seen option 2, but seen a lot of option 1. 我从未见过选项2,但是看到了很多选项1。
  2. Option 2 is for me a better one, because business logic includes working with database, index system and memory cache and I've got not idea how to check it during compilation time. 选项2对我来说是一个更好的选择,因为业务逻辑包括使用数据库,索引系统和内存缓存,并且我不知道如何在编译期间进行检查。

Technically, option 1 is not a compile time testing. 从技术上讲,选项1不是编译时测试。 Maven run the test before install/deploy the bundle after compile your code. Maven在编译代码之后在安装/部署捆绑软件之前运行测试。

Option 1 is for Unit testing. 选项1用于单元测试。 In detail, before install or deploy any bundle, need to make sure each and every unit of your code working as expected. 详细地说,在安装或部署任何捆绑软件之前,需要确保代码的每个单元均按预期工作。

Option 2 is for functionality testing. 选项2用于功能测试。 Test begins by invoking or testing the main gateway or main functionality, that will invoke the multiple modules internally. 测试从调用或测试主网关或主要功能开始,这些网关或主要功能将在内部调用多个模块。 Based on the input, some of the unit may execute or may not.. primary focus of this testing is to cover and make sure the different scenario of the functionality. 根据输入,某些单元可能会执行或可能不会执行。此测试的主要重点是覆盖并确保该功能的不同场景。

Good developer should do both. 优秀的开发人员应同时做到。 Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM