寻找有关在Intellij IDEA 9.x中使用JUnit的教程 [英] Looking for a tutorial on using JUnit with Intellij IDEA 9.x

查看:117
本文介绍了寻找有关在Intellij IDEA 9.x中使用JUnit的教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个绝对的初学者指南,一起使用JUnit和Intellij IDEA 9.x.我在WinXP上运行JDK 1.6.0_22。我正在寻找以下问题的答案:

I need an absolute beginners guide to using JUnit and Intellij IDEA 9.x together. I'm running JDK 1.6.0_22 on WinXP. I'm looking for answers to the following questions:


  1. 我是否需要安装JUnit或者它是否已集成到Intellij中?如果我需要设置它怎么样?

  2. 假设我有一个我想测试的类的接口和impl,我该如何设置一个JUnit项目?

  3. 有没有办法根据类接口自动生成测试骨架?

我有其他经验单元测试框架,如PHPUnit和Boost.Test,所以我主要关注在Intellij中设置和运行所有这些的机制。

I've got experience with other Unit testing frameworks like, PHPUnit and Boost.Test, so I'm primarily concerned with the mechanics of getting all this set up and running in Intellij.

编辑

我使用Intellij是一个完整的新手。

我来自命令行背景,即在Linux上使用vim和手写make文件的C ++ dev。

I'm coming from a command-line background, i.e. C++ dev using vim and handwritten make files on Linux.

我已经设法通过命令行编译并运行一些JUnit测试(下载了JUnit 4.8.2并使用了-cp swith),但我有点哎呀在Intellij下设置任何东西的时间。我试着查看在线Intellij文档,但没有找到那些很有用。我查看了Intellij的lib目录,它包含了Junit-4.7.jar。

I've managed to compile and run some JUnit tests via command line ( downloaded JUnit 4.8.2 and used the -cp swith), but I'm having a heck of a time getting anything set up under Intellij. I tried looking at the online Intellij docs, but haven't found those to be very useful. I looked in Intellij's lib directory and it includes Junit-4.7.jar.

我真的需要某种快速入门指南和一步一步的说明从最初的项目创建到成功运行第一次单元测试。

I really need some kind of quick start guide with step by step instructions from initial project creation through successfully running the first unit test.

推荐答案


  1. IDEA附带JUnit 支持,但请记住,您需要在项目上调用测试 - 因此您的项目需要在其类路径上使用JUnit。因此,您不需要安装JUnit,但是您需要像使用任何其他第三方库一样使其JAR可用于您的项目(例如,将其引用为Maven依赖项或将JAR放在<$ c中) $ c> lib / )。

  2. 这是IDEA支持的开始 - 我99%肯定你不需要做任何特殊的事情。由于使用JUnit通常只涉及使用 @ org.junit.Test 注释您的测试方法,因为这个快速教程,IDEA不再需要任何东西。对于在其至少一个方法上具有此注释的任何类,IDEA将为您提供将该类作为JUnit测试用例执行的选项。 (注意:此可能仅适用于项目结构中标记为Test Sources的目录中的文件,但我没有对此进行测试。最好设置项目无论如何这样。)

  3. 默认情况下不作为JUnit支持的一部分。还有其他插件可以做到这一点,但在我个人看来,这并不像听起来那么有用。 IDEA 确实集成了代码覆盖率(完整版),(再次恕我直言)是确保您的测试用例涵盖您的类/接口的全部功能的更好方法。

  1. IDEA comes with JUnit support, but bear in mind that you need to invoke tests on your project - and hence your project will need to have JUnit on its classpath. Hence you don't need to "install" JUnit, but you'll need to make its JAR available to your project as you would with any other third party library (e.g. reference it as a Maven dependency or drop the JAR in lib/).
  2. This is where the IDEA support kicks in - I'm 99% sure you don't need to do anything special. Since using JUnit in general simply involves annotating your test methods with @org.junit.Test, as per this quick tutorial, IDEA does not require anything further. For any class with this annotation on at least one of its methods, IDEA will give you the option to execute that class as a JUnit test case. (Note: this may only be the case for files in a directory that's marked as "Test Sources" in the project structure, but I haven't tested this. It's a good idea to set your project up like this anyway.)
  3. Not by default as part of the JUnit support. There exist other plugins to do this, but in my personal opinion this is not as useful as it might sound. IDEA does have integrated code coverage (with the full edition), which (again IMHO) is a better way to ensure that your tests cases cover the full functionality of your class/interface.

这篇关于寻找有关在Intellij IDEA 9.x中使用JUnit的教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆