简体   繁体   中英

JUnit Best Practice for Suites?

So I am combining my unit tests into suites. I was told if I could categorize the tests..

So I have the following tests that would be categorized for the

LoginSuite
- loginTest.java
- registerUser.java
- forgotPass.java

Then I have another suite called MessagesSuite with the following unit tests in it

MessageSuite
- searchMessages.java
- sendDirectMessage.java
- sendChannelMessage.java

Is it proper to categorize it so that both uni test suites are enclosed by an AllSuites file? Such that

AllSuites
- LoginSuite
- MessageSuite

If making sub-Suites and putting them within Suites is proper, how would I do this? I currently have my login suite that looks like the following:

package myPackages.loginSuite;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;


@RunWith(Suite.class)
@SuiteClasses({ 
    forgotPassTest.class, 
    loginTest.class, 
    registerNewUserTest.class })
public class LoginSuite {

}

If you have kept LoginSuite in myPackages.loginSuite package/folder, MessageSuite in myPackages.messageSuite package and AllSuites in myPackages.allSuites package. Then, your AllSuites code should be as shown below:

package myPackages.AllSuites;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

import myPackages.messageSuite.MessageSuite;
import myPackages.loginSuite.LoginSuite;

@RunWith(Suite.class)
@SuiteClasses({LoginSuite.class, MessageSuite.class})


public class AllSuite {
}

In the above code, as the suite classes ( LoginSuite and MessageSuite ) have different locations, following import statements have been added:

import myPackages.messageSuite.MessageSuite;
import myPackages.loginSuite.LoginSuite;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM