---
title: "Junit4中测试抛异常"
author: "samjavaeye"
date: "2014-07-14T15:43:18Z"
tags: []
categories: ["编程语言"]
slug: "junit4"
draft: false
lastmod: "2014-07-14T15:43:49Z"
id: 2091913
url: "https://samjavaeye.iteye.com/blog/2091913"
---

虽然很简单，但是久了不用很容易忘记……

其实就是在@Test后面加上expected=异常的class对象，例如：

```
@Test(expected=IllegalArgumentException.class)
public void testMethod() {
    ......
}
```