Devoxx 2012-第4天

Unitils: Thomas de RyckeJeroen Horemans针对企业应用程序的完整堆栈测试解决方案

有不同类型的测试:单元测试(隔离测试),集成测试(测试子系统)和系统测试(测试整个系统)。 层次结构越高,执行的时间就越长,因此您应该拥有大量的UT,一些IT以及一些系统测试。

单元测试必须具有超快的执行速度,易于阅读和重构的功能,并且还应告诉您在不调试的情况下出了什么问题。 另一方面,您必须编写许多测试。 在第一阶段不编写单元测试将使您更快,但是当应用程序增长时,它将大大降低您的生产率。 在企业设置中,最好使用UT。

为了避免测试框架爆炸,选择了Unitils测试框架。 JUnit或TestNG都可以挂接到Unitils中。 核心本身很小(以便快速),该体系结构基于模块。

让我们以“贺卡发送”应用程序为例。 -演示的代码很好地分层,带有服务和dao,并通过注解使用Spring自动装配和事务处理 -Maven提供了Unitils,因此将其添加到类路径仅是为POM添加正确的dep的问题。 Unitils提供一些注释:

  • @TestedObject在目标对象上设置
  • @Mock注入不同的协作者(使用EasyMock)
  • @InjectByType提示Unitils要使用的注入策略

尽管测试POJO(以及DTO)不是很划算,但是可以创建一个测试类来检查JavaBean约定。

如果您学习如何编写可测试的代码,则单元测试将变得无足轻重:设计良好的OO和依赖注入,在代码中进行接缝并完全避免使用全局状态(例如时间)。 集成和系统呢? 它们往往变得复杂,您将需要一个“魔术”抽象超类。 而且,当IT发生故障时,您不知道代码是否有错误或IT本身是否存在。 此外,您可能需要学习框架(JSF附带了自己的测试框架JSFUnit)。

作为软件开发人员,同样的问题又回来了:

  • 数据库:我的架构是最新的吗? 如何管理我的参照产业来建立和拆除数据?
  • 这些操作可能很慢
  • 最后,如何处理外部问题?

通过为每个问题使用专用模块,Unitils为每个问题提供了解决方案。 例如,Webdriver模块允许您通过Unitils使用Selenium,DBUnit模块对DBunit执行相同的操作,而Mail模块创建伪造的SMTP服务器。

-演讲者告诉我们,有了Unitils,就不再需要魔术抽象超类:恕我直言,它已经被魔术黑匣子测试框架所取代-

Unitils受益于一整套模块,涵盖了单个专用区域:Swing,Batch,File,Spring,Joda Time等。

Martijn VerburgBen Evans 撰写的现代软件开发反模式

有10种反模式可以涵盖:

反模式 恶魔般的程序员 理性之声 该怎么办

Conference-Driven Delivery

Real pros hack code and write their slides minutes before their talks

PPPPPP

In order to improve your presentation skills, you can rehearse in front of the mirror. Let’s call it Test-Driven presentations. Begin with a supportive crew, then grow into larger and larger audience.

Mortgage-Driven Development

In order for others not to steal your job, don’t do any documentation. Even better, control your source code i.e keep the source on a USB key

Don’t succumb to fear: proper communication is key.

Developers who communicate have the most success. If you want one of your idea to go into source control, you’ll have to communicate about it.

Distracted by shiny

Always use the latest tech, it’ll put you ahead. Consider using the latest version of Eclipse, packed full of plugins

Prototype and evaluate: learn to separate the myth from the reality. As an example, web frameworks are an area you should tread carefully.

Code reviews are an asset, especially if everyone do them so as to share best practices.

Brown bag sessions are good, in order to test every possible options.

Design-Driven Design

UML Code generators are awesome. Print your UML diagrams on gigantic sheets, put them on the wall, and if someone asks you a question, reply that it’s obvious

Design for what you need to know: don’t try to do too much upfront. Successful teams are able to navigate between methodologies that suit them.

Less source code: pay your junior developers to produce code, and pay your senior to remove it. The less code, the less chances to have bugs. Be wary of maintainability, though (Clojure is a good example).

Pokemon pattern

Use all of the GoF patterns

The appropriate design pattern is your friend. Using a design pattern is adding a feature to a language which is missing it. As an example, Java concurrency works, but since mutability is deeply rooted, it’s hard. Of course, you could use actors (like in Scala), but you definitely would add a feature.

Whiteboard, whiteboard and whiteboard, to communicate with your colleagues. As a tip, carry whiteboard markers at all time (or alternatively pen and pencil).

Tuning by Folklore

Performance tune by lightning black candles. Remove string concatenations, add DB connections and so on

Measure, don’t guess. It’s the best approach to improve performance. If it sounds boring, it’s because it is. Remember that the problem is probably not where you think it is.

Shameless plug : go to jClarity

Deity

All the code in one file is easier to search. VB 6 is one of the most popular language because of it

Discrete components based on SOLID principles : Single Responsibility, Open to extension, Litskov substitution, etc.

Discuss with your team, don’t go screaming WTF, you’ll probably have issues. You need to use naming based on the domain model so as other developers can read your code

Lean Startup Ninja

A ninja ships its code when it compiles!Continuous delivery is a business enabler.

Tools are available to achieve continuosu delivery: Ant/Gradle/Maven + Jenkins + Puppet + Vagrant

CV++

The Tiobe index is your friend.

Just be good at the principles. Try different languages, because when learning another language can be applied to the language you’re currently programming in.

Being a Software Developer is better than a Programmer. The former understands the whole lifecycle of an application, which is much better.

I haz Cloud

Nothing can go wrong if you push your applications in the cloud

Evaluate and prototype

There are many providers available: EC2, Heroku, JElastic, CloudBees, OpenShift, etc. Again, a brown bag session is a great way to start

Can Haz Mobile

If you go into the mobile game, you’ll be a millionaire

HTML5 for the win

UX is so important. What are your UX needs?

Think about what pisses you off…​

Big Data

MongoDB is web scale

What type of data are you storing?

Bill Venners简化 Scala设计

最主要的是显示如何:

  • 设计为您的用户简化任务
  • 专为繁忙的团队而设计。 不要以为您的用户是您图书馆的专家。 就像驾驶从未有过的汽车:显而易见,用户无需查看文档
  • 根据喜好顺序,使其变得明显,容易猜测或易于记忆。 ScalaTest中plusOrMinus的选择过程就是一个很好的例子。
  • 按顺序为读者,然后是作家设计。 选择invokePrivate的名称是一个很好的例子:比某些符号更好地使用语义上有意义的内容
  • 使错误变为不可能(或最终使困难)。 特别是,使用Scala的丰富类型系统来实现此目的。 使用编译器标记错误是最好的
  • 利用熟悉度。 James Gosling在Java中使用了熟悉的C ++关键字,但没有进行内存管理以利用这一原理。 ScalaTest使用JUnit构造但在每个测试上强制添加标签的方式也是如此。
  • 带有示例的文件
  • 减少冗余。 Python Zen指出:
    应该只有一种明显的方法,最好只有一种。

    一个好的做法是为每个类放置一个“推荐用法”块。

  • 最大化一致性。 ScalaTest提供了GivenWhenThen特性和Suite类。 但是,当您将后者与前者混合时,则无需设置测试名称。 但是,执行“单一责任原则”并引入“ Spec可以解决此问题。
  • 当您的用户已经是专家时,请使用它们。 Scala提供+而不是plus*而不是multiply 相反,在SBT中,某些符号被证明是有问题的: ~=<⇐<+=<<++= 同样,使用foldLeft()/:更好。 但是,在某些情况下,您根本无法使用单词(例如在代数中)。
  • 默认情况下使用功能样式,但改用命令式样式以提高可用性。 例如,套件中的test功能会记录在花括号内键入的测试。

    记住要使用什么工具。 他们是为了解决问题,而不是寻找要解决的问题

Igor MinarMisko Hevery用AngularJS重新设计浏览器

-我参加本次会议是为了让我对HATEOAS应用程序更加开放。 我确实希望这是值得的! -

浏览器一次真的很简单。 16年后,浏览器提供了更多功能,甚至允许人们通过浏览器进行开发! 对于用户而言,这是一件好事,对于开发人员而言,它并不是件很复杂的事情。

在静态页面中,您告诉浏览器您想要什么。 在JavaScript中,您必须注意浏览器的工作方式以及它们之间的区别(Hello IE)。 例如,还记得CSS border-radius之前border-radius吗? 在HTML或DOM API中,似乎没有这种改进。 即使使用jQuery,您也必须执行命令式编程。 寻找的解决方案是声明性的! 数据绑定有助于解决这种情况。 如果您的模型发生更改,则视图应自动更新。 相反,对于双向数据绑定,视图中的更新应更改基础模型。 高级模板可以与集合一起使用。 实际上,JavaScript的90%仅用于模型和视图之间的同步。

AngularJS现在会处理这个问题,而规范正在制定中,这应该成为浏览器工作方式的一部分。 HTML可能很冗长,制表符就是一个很好的例子:它们当前使用div而应该使用tab 。 从更一般的角度来看,AngularJS将此类组件引入表中。 另外,Web组件是对该功能进行标准化的尝试。

-这是一个演示-

AngularJS通过导入所需的js文件,在JS中创建模块并将自定义属性添加到HTML标签来工作。

Testacular是适用于AngularJSJavaScript测试框架。

David Blevins的 Tomcat上的Apache TomEE,JavaEE 6 Web配置文件

Apache TomEE试图解决该问题,因为您使用Tomcat来运行,而不是碰壁然后转到另一台服务器。 TomEE是经过认证的Web Profile堆栈,它是Tomcat与Apache库之间的桥梁。 核心价值包括体积小,获得认证并保持Tomcat。

反正什么是Web配置文件? 为了解决JavaEE的庞大形象,v6规范引入了仅缩减全部JavaEE规范(第12页,共24页)的一半的规范。 不包含的内容:

  • CMP
  • 科巴
  • JAX-RPC
  • JAX-RS
  • JAX-WS
  • JMS
  • 连接器

后四项特别缺乏,因此TomEE分为三种:Web Profile,包括JavaMail(已认证),JAX-RS(已认证)和Plus,其中包括JAX-WS,Connector和JMS( 认证)。 请注意,在JavaEE 7中肯定会更改这些分布,因为配置文件本身也会更改。 TomEE于2011年以1.0.0.beta 1开始,十月份发布了1.5.0。 TomEE以其性能而闻名,但缺乏扩展的支持。

-这是TomEE演示,包括与Eclipse的集成(与Tomcat完全相同)–

TomcatEE只是与Tomcat的两个一对夫妇的JAR libendorsed ,额外配置conf并为每个操作系统的启动bin 。 此外,还有Java代理( 由于某种原因,我无法捕获- )。

测试是使用Arquillian完成的,并且在一小时内即可运行。 认证测试是在Amazon EC2实例上执行的,每个实例具有613个最大内存(并在+百小时内运行):请注意,TCK通过默认的JVM内存。 下载27Mb的结果非常有趣,运行时仅占用64Mb的内存。 自己集成所有堆栈是一个坏主意,这不仅是因为浪费时间,而且是因为单独汇总所有组件与在TomEE中完成集成之间存在差距。

TomEE的重要功能包括Arquillian和Maven的集成。 TomEE的一个关键点是,部署错误会同时全部打印出来,并且不会像其他应用程序服务器那样强迫您一一纠正这些错误。

翻译自: https://blog.frankel.ch/devoxx-2012/4/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值