Can we use JUNIT for Automated Integration Testing

2019-01-30 02:04发布

How do you automate integration testing? I use JUnit for some of these tests. This is one of the solutions or is totally wrong? What do you suggest?

10条回答
smile是对你的礼貌
2楼-- · 2019-01-30 02:45

JUnit works. There are no limitations that restrict it to being unit tests only. We use JUnit, Maven and CruiseControl to do CI.

There may be tools that are specific for integration testing, but I would think their usefulness is dependent on what type of system components you are integrating. JUnit will work fine for non UI type testing.

查看更多
淡お忘
3楼-- · 2019-01-30 02:50

Definitely! We use a combination of JUnit, ANT tasks to run them, and Hudson for continues integration tests. Works like a charm.

查看更多
Evening l夕情丶
4楼-- · 2019-01-30 02:52

When using Maven to build a project, I've had a little more luck with TestNG because it has @BeforeSuite and @AfterSuite operations. Which are useful because Maven will not execute the 'post-integration-test` if any of the integration tests fail. Not a problem with Ant, so I just use jUnit out of preference with it.

In either case, segmenting out the tests as both TestNG and jUnit do is helpful with integration tests too.

查看更多
Ridiculous、
5楼-- · 2019-01-30 02:55

Yes, you may use junit for integration tests, but it depends on the type of integration test you need.

Testing a servlet:

  • setup the servlet context and config
  • do the tests using mock servlet requests (Spring has support for this, but you may also use EasyMock or your own mocks)

Testing a spring application:

  • use AbstractDependencyInjectionSpringContextTests to setup the context
  • test the wired beans
  • there are also subclasses of AbstractDependencyInjectionSpringContextTests supporting transaction handling when testing with a database.

But pure Junit has its limit. Testing user interfaces is a typical case. You may use selenium for web applications, soapui for webservices or other appropriate tools.

But whatever you use, it should be possible to integrate it in your continious build (cruise control, team city or whatever).

查看更多
Root(大扎)
6楼-- · 2019-01-30 02:55

Update for 2012: Whilst JUnit can be used (and benefits from CI support) JWebUnit and Selenium appear to be eating up the mindshare for Integration Testing.

查看更多
混吃等死
7楼-- · 2019-01-30 02:56

I think automation and integration tests do not play well together. The very basic problem is environment setup before every test. The more integration-type test bigger setup is needed.

My thoughts on test automation on integration layer: http://blog.aplikacja.info/2012/03/whats-wrong-with-automated-integration-tests/

查看更多
登录 后发表回答