diff --git a/t/samlmetadata.t b/t/samlmetadata.t
new file mode 100644
index 0000000000000000000000000000000000000000..a28ecd82ce8f154134c123f9792271982856bcd6
--- /dev/null
+++ b/t/samlmetadata.t
@@ -0,0 +1,76 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use English qw(-no_match_vars);
+use File::Temp;
+use Test::More;
+use Test::Exception;
+
+use IdPAccountManager::SAMLMetadata;
+
+plan tests => 6;
+
+my $metadata;
+
+throws_ok {
+    $metadata = IdPAccountManager::SAMLMetadata->new();
+} qr/^missing argument 'file'/,
+'instanciation: no file argument';
+
+throws_ok {
+    $metadata = IdPAccountManager::SAMLMetadata->new(
+        file => '/no/such/file',
+    );
+} qr/^non-existing file/,
+'instanciation: non-existing file argument';
+
+my $file1 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
+
+chmod 0000, $file1;
+
+throws_ok {
+    $metadata = IdPAccountManager::SAMLMetadata->new(
+        file => $file1->filename()
+    );
+} qr/^non-readable file/,
+'instanciation: non-readable file';
+
+chmod 0644, $file1;
+
+throws_ok {
+    $metadata = IdPAccountManager::SAMLMetadata->new(
+        file => $file1->filename()
+    );
+} qr/^Failed to parse file \S+: Empty Stream/,
+'instanciation: empty file';
+
+my $file2 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
+
+print $file2 <<EOF;
+foo
+EOF
+close($file2);
+
+throws_ok {
+    $metadata = IdPAccountManager::SAMLMetadata->new(
+        file => $file2->filename()
+    );
+} qr/^Failed to parse file \S+: Entity: line 1: parser error/,
+'instanciation: non-xml file';
+
+my $file3 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
+
+print $file3 <<EOF;
+<?xml version="1.0" encoding="UTF-8" ?>
+<root/>
+EOF
+close($file3);
+
+throws_ok {
+    $metadata = IdPAccountManager::SAMLMetadata->new(
+        file => $file3->filename()
+    );
+} qr/^incorrect root element type 'root'/,
+'instanciation: incorrect xml file';