我的phpunit测试:
<?php
class TestTest extends PHPUnit_Framework_TestCase
{
/*
* @expectedExceptionMessage success
*/
public function testExceptionMessage() {
throw new Exception('success');
}
}
单元测试失败。这是phpunit的输出:
There was 1 error:
1) TestTest::testExceptionMessage
Exception: success
/path/to/TestTest.php:8
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
在我看来,测试应该是成功的,因为Exception消息是成功的,这是@expectedExceptionMessage所期望的?
答案 0 :(得分:3)
添加@expectedException
注释,它应该可以正常工作
/**
* @expectedException Exception
* @expectedExceptionMessage success
*/
public function testExceptionMessage() {
throw new Exception('success');
}
答案 1 :(得分:1)
在抛出PHPUnit之前,您需要发出警报:
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = @"Title";
content.body = @"Body";
content.sound = [UNNotificationSound defaultSound];
NSURL *imageURL = [NSURL fileURLWithPath:@"example.png"];
NSError *error;
UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"image" URL:imageURL options:nil error:&error];
if (error)
{
NSLog(@"error while storing image attachment in notification: %@", error);
}
if (icon)
{
content.attachments = @[icon];
}