我想在Junit 5中运行带有少量类的@RunWith并附加我所做的依赖项以及代码,但是只有一个类正在运行= someTest,我在这里错过了什么?
someTest类
import org.junit.jupiter.api.Test;
import org.junit.platform.suite.api.SelectClasses;
@RunWith(JUnitPlatform.class)
@SelectClasses( { Something.class, someTest.class } )
public class someTest {
@Test
public void sadsadas() {
System.out.println("these is the runWith");
}
}
给一些东西
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
public class Something {
Logger logger = Logger.getLogger("");
FileHandler fh;
@BeforeEach
public void wallad() {
System.out.println("hello");
}
@AfterEach
public void asddf() {
System.out.println("pizza");
}
@Tag("test")
@Test
public void some() {
try {
fh = new
FileHandler("C:\\Users\\tester\\Desktop\\MyLogFile.txt");
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
} catch (Exception e) {
e.printStackTrace();
}
logger = Logger.getLogger(Logger.class.getName());
logger.setLevel(Level.ALL);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
logger.addHandler(handler);
logger.setUseParentHandlers(false);
System.out.println("test1");
logger.log(Level.WARNING, "warning");
System.out.println("test2");
logger.log(Level.INFO, "information");
System.out.println("test3");
logger.log(Level.SEVERE, "severe");
System.out.println("test4");
logger.log(Level.FINEST, "finest");
System.out.println("test5");
logger.log(Level.FINE, "fine");
System.out.println("test6");
logger.log(Level.FINER, "finer");
System.out.println("test7");
logger.log(Level.FINEST, "finest");
}
}
这些是附加到maven的依赖项
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>1.4.0-M1</version>
</dependency>
在运行方面我错过了什么?还是在junit5中我只需要写:
@SelectClasses( { Something.class, someTest.class } )
我正在运行Eclipse Jee 2018-09
答案 0 :(得分:0)
将Something.class
重命名为SomethingTest.class
即可。
@SelectClasses({ SomethingTest.class, someTest.class })