0

I want to to integration tests against an http server. So far I have only experiences with junit for unit testing.

I have two requirements: The framework must have a maven plugin and the tests cases code must be clean - so no dirty hacks and no boilerplate code.

Plain JUnit is good for unit testings, @Test methods are individual. But for integration testing I have to process several dependant steps which must exchange some kind of state (variables).

I already read:

Can we use JUNIT for Automated Integration Testing? and Passing JUnit data between tests and came to the conclusion that I don't like static fields in unit test and I don't want to use TestNG and add dependency annotations on tests and I don't want to put my test into one long unreadable test method.

I though more about some syntax like:

public class MyIntegrationTest() {

   @Step
   public void testCreate(Context context) {context.put("foo");}

   @Step
   public void testUpdate(Context context) {context.get();}

   @Step
   public void testDelete(Context context) {context.get()}

}

So I want to enhance/use ?Unit in a way that it executes @Step methods with a context instance as argument. The methods must be called by the framework in order and cannot be called individually. In a perfect world, all ?Unit guis would show the @Step like an @Test but this is optional...

Any hints how to do this?

Jan

Community
  • 1
  • 1
Jan
  • 2,803
  • 6
  • 36
  • 57
  • with the Answers given below I set up the following environment: @Step annotations, my own JUnitRunner and I start the test cases via maven+hudson using the exec:java plugin + commandling executor. – Jan Oct 11 '11 at 08:37
  • So if your first test case fails. "Put". All your following test cases will also fail? Test cases should be independed from each other. – Andreas Waldahl May 13 '15 at 14:39
  • Hi Andreas, Test Cases should, Test steps not. Don't get confused with the default junit structure (One method == one TestCase). But in case somebody else digs out this old post: I dropped the described approach and use the spring webmvc testing http://docs.spring.io/spring/docs/current/spring-framework-reference/html/testing.html now (not a 100% replacement for my original needs). – Jan May 18 '15 at 12:23

2 Answers2

1

The first point is to check the Maven Failsafe Plugin which is intended for doing integration tests with Maven. Second you have to name your Integration tests based on the conventions used by Maven FailSafe Plugin after that you should be able to run your integration tests simply with maven (by mvn clean verify). So this means you have to name your integration test like MyIntegrationIT.java...To define the order of executions you have to use a different framework than JUnit may be TestNG which supports this kind of needs, but you already excluded it. So the questions is what kind of tests would you like to do? Page-flows etc. may be a look at JWebUnit might be look worth...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • TestNG is not included per se but I don't want to manually define dependencies. I just test simple http CRUD calls. – Jan May 03 '11 at 20:42
1

You might also want to consider http://httpunit.sourceforge.net/. It's useful for checking to see if responses come back from the http server.

However, it doesn't do the @Step functionality. Normally I'd do that by :

@Test
public void MasterTest() {
  step1(..);
  step2(..);
  ....
}



public void step1(...){...}
   public void step2(...){...}
Karthik Ramachandran
  • 11,925
  • 10
  • 45
  • 53
  • That could easily be automated via reflection, I guess – Jan May 03 '11 at 20:43
  • yup. No doubt you can write a custom test runner (the junit piece that actually executes your test) and have to do exactly what you want. It could inspect each method in the class for @Step and execute them in order. Not saying its hard, just saying its not in any of the libraries I'm familiar with. – Karthik Ramachandran May 03 '11 at 20:50