亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

initialization Error java.lang.Exception: No runnable methods 怎么解決 Junit失敗、 控制臺沒信息?

package org.junit.runner.manipulation;

import org.junit.runner.Description;
import org.junit.runner.Request;

/**
?* The canonical case of filtering is when you want to run a single test method in a class. Rather
?* than introduce runner API just for that one case, JUnit provides a general filtering mechanism.
?* If you want to filter the tests to be run, extend <code>Filter</code> and apply an instance of
?* your filter to the {@link org.junit.runner.Request} before running it (see
?* {@link org.junit.runner.JUnitCore#run(Request)}. Alternatively, apply a <code>Filter</code> to
?* a {@link org.junit.runner.Runner} before running tests (for example, in conjunction with
?* {@link org.junit.runner.RunWith}.
?*
?* @since 4.0
?*/
public abstract class Filter {
??? /**
???? * A null <code>Filter</code> that passes all tests through.
???? */
??? public static Filter ALL = new Filter() {
??????? @Override
??????? public boolean shouldRun(Description description) {
??????????? return true;
??????? }

??????? @Override
??????? public String describe() {
??????????? return "all tests";
??????? }

??????? @Override
??????? public void apply(Object child) throws NoTestsRemainException {
??????????? // do nothing
??????? }

??????? @Override
??????? public Filter intersect(Filter second) {
??????????? return second;
??????? }
??? };

??? /**
???? * Returns a {@code Filter} that only runs the single method described by
???? * {@code desiredDescription}
???? */
??? public static Filter matchMethodDescription(final Description desiredDescription) {
??????? return new Filter() {
??????????? @Override
??????????? public boolean shouldRun(Description description) {
??????????????? if (description.isTest()) {
??????????????????? return desiredDescription.equals(description);
??????????????? }

??????????????? // explicitly check if any children want to run
??????????????? for (Description each : description.getChildren()) {
??????????????????? if (shouldRun(each)) {
??????????????????????? return true;
??????????????????? }
??????????????? }
??????????????? return false;
??????????? }

??????????? @Override
??????????? public String describe() {
??????????????? return String.format("Method %s", desiredDescription.getDisplayName());
??????????? }
??????? };
??? }


??? /**
???? * @param description the description of the test to be run
???? * @return <code>true</code> if the test should be run
???? */
??? public abstract boolean shouldRun(Description description);

??? /**
???? * Returns a textual description of this Filter
???? *
???? * @return a textual description of this Filter
???? */
??? public abstract String describe();

??? /**
???? * Invoke with a {@link org.junit.runner.Runner} to cause all tests it intends to run
???? * to first be checked with the filter. Only those that pass the filter will be run.
???? *
???? * @param child the runner to be filtered by the receiver
???? * @throws NoTestsRemainException if the receiver removes all tests
???? */
??? public void apply(Object child) throws NoTestsRemainException {
??????? if (!(child instanceof Filterable)) {
??????????? return;
??????? }
??????? Filterable filterable = (Filterable) child;
??????? filterable.filter(this);
??? }

??? /**
???? * Returns a new Filter that accepts the intersection of the tests accepted
???? * by this Filter and {@code second}
???? */
??? public Filter intersect(final Filter second) {
??????? if (second == this || second == ALL) {
??????????? return this;
??????? }
??????? final Filter first = this;
??????? return new Filter() {
??????????? @Override
??????????? public boolean shouldRun(Description description) {
??????????????? return first.shouldRun(description)
??????????????????????? && second.shouldRun(description);
??????????? }

??????????? @Override
??????????? public String describe() {
??????????????? return first.describe() + " and " + second.describe();
??????????? }
??????? };
??? }
}

正在回答

7 回答

<project?xmlns="http://maven.apache.org/POM/4.0.0"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0?http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.xy9860</groupId>
	<artifactId>seckill</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>seckill?Maven?Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<!--?日志相關的依賴?-->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.12</version>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-core</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!--?實現slf4j?這樣我們只需要使用?slf4j的接口就可以了?-->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!--?數據庫相關的依賴?-->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.41</version>
		</dependency>
		<dependency>
			<groupId>com.mchange</groupId>
			<artifactId>c3p0</artifactId>
			<version>0.9.5.2</version>
		</dependency>
		<!--?DAO框架依賴?mabits?-->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.4.2</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.3.1</version>
		</dependency>
		<!--?SERVlet?web相關的依賴?-->
		<dependency>
			<groupId>taglibs</groupId>
			<artifactId>standard</artifactId>
			<version>1.1.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.8.8</version>
		</dependency>
		<!--?spring?依賴?-->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.3.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>4.3.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>4.3.7.RELEASE</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>seckill</finalName>
	</build>
	<packaging>war</packaging>
</project>


0 回復 有任何疑惑可以回復我~

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?? ?xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
?? ?<modelVersion>4.0.0</modelVersion>
?? ?<groupId>seckill</groupId>
?? ?<artifactId>seckill</artifactId>
?? ?<packaging>war</packaging>
?? ?<version>1.0-SNAPSHOT</version>
?? ?<name>seckill Maven Webapp</name>
?? ?<url>http://maven.apache.org</url>
?? ?<dependencies>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>junit</groupId>
?? ??? ??? ?<artifactId>junit</artifactId>
?? ??? ??? ?<version>4.11</version>
?? ??? ??? ?<scope>test</scope>
?? ??? ?</dependency>
?? ??? ?<!-- 日志 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.slf4j</groupId>
?? ??? ??? ?<artifactId>slf4j-api</artifactId>
?? ??? ??? ?<version>1.7.12</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>ch.qos.logback</groupId>
?? ??? ??? ?<artifactId>logback-core</artifactId>
?? ??? ??? ?<version>1.1.1</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>ch.qos.logback</groupId>
?? ??? ??? ?<artifactId>logback-classic</artifactId>
?? ??? ??? ?<version>1.1.1</version>
?? ??? ?</dependency>
?? ??? ?<!-- 數據庫依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>mysql</groupId>
?? ??? ??? ?<artifactId>mysql-connector-java</artifactId>
?? ??? ??? ?<version>5.1.40</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>c3p0</groupId>
?? ??? ??? ?<artifactId>c3p0</artifactId>
?? ??? ??? ?<version>0.9.1.2</version>
?? ??? ?</dependency>
?? ??? ?<!-- mybatis依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.mybatis</groupId>
?? ??? ??? ?<artifactId>mybatis</artifactId>
?? ??? ??? ?<version>3.3.0</version>
?? ??? ?</dependency>
?? ??? ?<!-- mybatis自身實現的整合依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.mybatis</groupId>
?? ??? ??? ?<artifactId>mybatis-spring</artifactId>
?? ??? ??? ?<version>1.2.3</version>
?? ??? ?</dependency>
?? ??? ?<!-- servlet web 相關依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>taglibs</groupId>
?? ??? ??? ?<artifactId>standard</artifactId>
?? ??? ??? ?<version>1.1.2</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>jstl</groupId>
?? ??? ??? ?<artifactId>jstl</artifactId>
?? ??? ??? ?<version>1.2</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.fasterxml.jackson.core</groupId>
?? ??? ??? ?<artifactId>jackson-databind</artifactId>
?? ??? ??? ?<version>2.5.4</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>javax.servlet</groupId>
?? ??? ??? ?<artifactId>javax.servlet-api</artifactId>
?? ??? ??? ?<version>3.0.1</version>
?? ??? ?</dependency>
?? ??? ?<!-- spring 依賴 -->
?? ??? ?<!-- 因為有些包已經把spring做為默認依賴,這里面可以省略的依賴有:
?? ??? ??? ?spring-core;spring-beans(上面這兩個spring-context會自動依賴);
?? ??? ??? ?spring-context,spring-jdbc(mybatis-spring會依賴); spring-web(spring-webmvc會依賴);
?? ??? ??? ?logback-core(logback-classic會依賴). -->
?? ??? ?<!-- spring 核心依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-core</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-beans</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-context</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<!-- spring dao 層依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-jdbc</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-tx</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<!-- spring web 相關依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-web</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-webmvc</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ??? ?<!-- spring test 相關依賴 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-test</artifactId>
?? ??? ??? ?<version>4.1.7.RELEASE</version>
?? ??? ?</dependency>
?? ?</dependencies>
?? ?<build>
?? ??? ?<finalName>seckill</finalName>
?? ??? ???? <plugins> ?
??????????????? <plugin> ?
??????????????????? <groupId>org.apache.maven.plugins</groupId> ?
??????????????????? <artifactId>maven-compiler-plugin</artifactId> ?
??????????????????? <version>3.1</version> ?
??????????????????? <configuration> ?
??????????????????????? <source>1.8</source><!--? 這個1.8是jdk的版本,下面那個也是--> ?
??????????????????????? <target>1.8</target> ?
??????????????????? </configuration> ?
??????????????? </plugin> ?
??????????? </plugins> ?
?? ?</build>
</project>



0 回復 有任何疑惑可以回復我~
package?com.xy9860.seckill.service.impl;

import?java.util.List;

import?javax.annotation.Resource;

import?org.junit.Test;
import?org.junit.runner.RunWith;
import?org.slf4j.Logger;
import?org.slf4j.LoggerFactory;
import?org.springframework.test.context.ContextConfiguration;
import?org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import?com.xy9860.seckill.dto.Exposer;
import?com.xy9860.seckill.dto.SeckillExecution;
import?com.xy9860.seckill.entity.Seckill;
import?com.xy9860.seckill.service.SeckillService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public?class?SeckillServiceImplTest?{

	private?Logger?logger=LoggerFactory.getLogger(this.getClass());
	
	@Resource
	private?SeckillService?seckillService;
	
	@Test
	public?void?testGetSeckillList()?{
		List<Seckill>?seckills?=seckillService.getSeckillList();
		logger.info("list={}",seckills);
	}

	@Test
	public?void?testGetSeckillById()?{
		?Seckill?seckill=seckillService.getSeckillById(1000);
		?logger.info("seckill={}",seckill);
	}

	@Test
	public?void?testExportSeckillUrl()?{
		long?id=1000;
		Exposer?exposer=seckillService.exportSeckillUrl(id);
		logger.info("exposer={}",exposer);
	}

	@Test
	public?void?testExecuteSeckill()?{
		String?md5="652785cd5da374c9a9f48b5bf57285bb";
		long?id=1000;
		long?phone=13333333233L;
		SeckillExecution?seckillExecution=seckillService.executeSeckill(id,?phone,?md5);
		logger.info("seckillExecution={}",seckillExecution);
	}

}


0 回復 有任何疑惑可以回復我~
#1

葉雪松 提問者

我在按照視頻重寫一遍,有問題再請教。
2017-04-10 回復 有任何疑惑可以回復我~
package?com.xy9860.seckill.service.impl;

import?java.util.Date;
import?java.util.List;

import?org.slf4j.Logger;
import?org.slf4j.LoggerFactory;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.stereotype.Service;
import?org.springframework.transaction.annotation.Transactional;
import?org.springframework.util.DigestUtils;

import?com.xy9860.seckill.dao.SeckillDao;
import?com.xy9860.seckill.dao.SuccessKilledDao;
import?com.xy9860.seckill.dto.Exposer;
import?com.xy9860.seckill.dto.SeckillExecution;
import?com.xy9860.seckill.entity.Seckill;
import?com.xy9860.seckill.entity.SuccessKilled;
import?com.xy9860.seckill.enums.SeckillStatEnum;
import?com.xy9860.seckill.exception.RepeatKillException;
import?com.xy9860.seckill.exception.SeckillCloseException;
import?com.xy9860.seckill.exception.SeckillException;
import?com.xy9860.seckill.service.SeckillService;

@Service("seckillService")
public?class?SeckillServiceImpl?implements?SeckillService?{

	private?Logger?logger=LoggerFactory.getLogger(this.getClass());

	@Autowired
	private?SeckillDao?seckillDao;
	@Autowired
	private?SuccessKilledDao?successKilledDao;
	//用于混淆方法
	private?final?String?slat="asdasfJASLFKDAJ@#(*&%(@#%><?ˉ&asdjalfg";

	public?List<Seckill>?getSeckillList()?{
		//?TODO?Auto-generated?method?stub
		return?seckillDao.queryAll(0,?100);
	}

	public?Seckill?getSeckillById(long?seckillId)?{
		//?TODO?Auto-generated?method?stub
		return?seckillDao.queryByid(seckillId);
	}

	public?Exposer?exportSeckillUrl(long?seckillId)?{

		Seckill?seckill=seckillDao.queryByid(seckillId);
		if?(seckill==null)?{
			return?new?Exposer(false,seckillId);
		}
		Date?startTime=seckill.getStrartTime();
		Date?endTime=seckill.getEndTime();
		Date?nowTime=new?Date();
		if?(nowTime.getTime()>endTime.getTime()||nowTime.getTime()<startTime.getTime())?{
			return?new?Exposer(false,seckillId,nowTime.getTime(),startTime.getTime(),endTime.getTime());
		}
		String?md5=getMD5(seckillId);
		return?new?Exposer(true,md5,seckillId);
	}

	@Transactional
	public?SeckillExecution?executeSeckill(long?seckillId,?long?userPhone,?String?md5)
			throws?SeckillException,?SeckillCloseException,?RepeatKillException?{
		if?(md5==null||!md5.equals(getMD5(seckillId)))?{
			throw?new?SeckillException("seckill?date?rewrite");
		}
		//執行秒殺邏輯
		int?updateCount=seckillDao.reduceNumber(seckillId,?new?Date());
		try?{
			if?(updateCount<=0)?{
				//沒有更新操作
				throw?new?SeckillCloseException("seckill?is?closed");
			}else{
				//記錄購買行為
				int?insertCount?=successKilledDao.insertSuccessKilled(seckillId,?userPhone);
				if?(insertCount<=0)?{
					//重復秒殺
					throw?new?RepeatKillException("seckillId?repeated");
				}else?{
					SuccessKilled?successKilled=successKilledDao.queryByid(seckillId,?userPhone);
					return?new?SeckillExecution(seckillId,?SeckillStatEnum.SUCCESS,successKilled);
				}
			}
		}?catch?(Exception?e)?{
			logger.error(e.getMessage(),e);
			throw?new?SeckillException("seckill?iner?error"+e.getMessage());
		}
	}

	private?String?getMD5(long?seckillId){
		String?base=seckillId+"/"+slat;
		String?md5=DigestUtils.md5DigestAsHex(base.getBytes());
		return?md5;
	}
}


0 回復 有任何疑惑可以回復我~
#1

葉雪松 提問者

老哥稍等
2017-04-10 回復 有任何疑惑可以回復我~

你把你的pom.xml 關于 junit 和 spring 的版本 貼上來看看. ?看起來好像是 junit版本問題

0 回復 有任何疑惑可以回復我~

package org.seckill.service;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.seckill.dto.Exposer;
import org.seckill.dto.SeckillExecution;
import org.seckill.entity.Seckill;
import org.seckill.service.SeckillService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring/spring-dao.xml","classpath:spring/spring-service.xml"})
@Transactional
//@transactional加到測試類中,可讓每一次測試之后rollback,即不需要之后把數據庫數據改回來
public class SeckillServiceTest {
?? ?
?? ?private final Logger logger = LoggerFactory.getLogger(this.getClass());
?? ?
?? ?@Autowired
?? ?private SeckillService seckillService;

?? ?@Test
?? ?public void testGetSeckillList(){
?? ??? ?List<Seckill> list = seckillService.getSeckillList();
?? ??? ?logger.info("list={}", list);
?? ?}

?? ?@Test
?? ?public void testGetById() {
?? ??? ?long id = 1001;
?? ??? ?Seckill seckill = seckillService.getById(id);
?? ??? ?logger.info("seckill={}", seckill);
?? ?}

?? ?@Test
?? ?public void testExportSeckillUrl() {
?? ??? ?long id = 1000L;
?? ??? ?Exposer exposer = seckillService.exportSeckillUrl(id?? ?);
?? ??? ?logger.info("exposer={}", exposer);

?? ?}

?? ?@Test
?? ?public void testExecutionSeckill() {
?? ??? ?long id? = 1000L;
?? ??? ?long userId = 2013001L;
?? ??? ?String md5 = "whoamI?IamtheCodeKingoftheworld.Butnotjustcancoding,alsoBigBird";
?? ??? ?SeckillExecution seckillExecution = seckillService.executionSeckill(id, userId, md5);
?? ??? ?logger.info("successKilled={}", seckillExecution);
?? ?}

}



0 回復 有任何疑惑可以回復我~

沒看懂 你想測試什么,難道是我功力不夠?沒有@Test的入口啊?

0 回復 有任何疑惑可以回復我~
#1

葉雪松 提問者

等下我上代碼給你看,我有@test的,什么缺少jar包,junit版本問題我都試過了,都沒辦法解決。現在正在重寫service層。
2017-04-10 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

initialization Error java.lang.Exception: No runnable methods 怎么解決 Junit失敗、 控制臺沒信息?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號