java - Maven/junit project organization -


i have 3 packages:

  • foo provides api
  • foomysql (depends on foo) implements foo api using mysql
  • foopostgresql (depends on foo) implements foo api using postgresql

i have bunch of junit tests, should run twice: once again foomysql, , once again foopostgresql. same tests, because api should behave identically both implementations, setup , teardown different.

question: should define tests? logical place appears in foo. however, in foo, not executable because foo doesn't know of implementation. can put them foomysql, appears have have full copy on foopostgresql, "test" code defined in foo cannot referred via maven dependency mechanism foomysql etc. (is correct, or perhaps i'm missing trick?)

alternatively create separate footests project, foomysql , foopostgresql tests depend on. somehow sounds wrong, too. there better idea?

the first thing should know should unit-test implementations. always. think you're leaning wasn't sure since mentioned testing foo, want make sure it's established.

so let's without doing tests twice.

public abstract class footestbase {   protected abstract foo getfoo();   @test public void testbarmethod() {     // tests calling getfoo().   } }  public class foomysqltest extends footestbase {   @before public void setup() {     // stuff   }   @after public void teardown() {     // stuff   }   @override protected foo getfoo() {     return new foomysql();   } }  public class foopostgresqltest extends footestbase {   @before public void setup() {     // stuff   }   @after public void teardown() {     // stuff   }   @override protected foo getfoo() {     return new foopostgresql();   } } 

since use maven, default footestbase not considered test class because doesn't start test or ends test or testcase. therefore tests centralized in footestbase , executed in each child class.

your tests written once, , setup/teardown specific each implementation.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -