Presentation is loading. Please wait.

Presentation is loading. Please wait.

Automatisk tests og Continuous delivery Med afsæt i Bitmagasin og Netarkiv projekterne.

Similar presentations


Presentation on theme: "Automatisk tests og Continuous delivery Med afsæt i Bitmagasin og Netarkiv projekterne."— Presentation transcript:

1 Automatisk tests og Continuous delivery Med afsæt i Bitmagasin og Netarkiv projekterne

2 Emnerne • Design for testing. • Test design og best practices. • Unit tests vs. system tests. • Continuous integration. • Continuous delivery.

3 Design for test • Lettere tests • Test er initielle bruger af test • Bedre design – Blackbox test -> præcise API’er. – Seperation af hensyn – Modulart design Eksempler • Teori og Praksis

4 Kontrakt -> test kriterier public class WorldHelper { public void update() { ….. }

5 Kontrakt -> test kriterier public class WorldHelper { public void improveWorld() { …..

6 Kontrakt -> test kriterier public class WorldHelper { public void improveWorld(int flowers2Add) { world.flowers.add(7); …..

7 Dependency injection public class WorldHelper { private WorldImprover improver; public void improveWorld() { improver.improve(world); ….. } public void setImprover(WorldImprover improver) { this.improver = improver;

8 Dependency injection public class WorldHelper { private final WorldImprover improver; public WorldHelper (WorldImprover improver) { this.improver = improver; } public void improveWorld() { improver.improve(world); ….. }

9 Singleton, hrrrmmm public class WorldHelper { public WorldHelper () { world = World.getInstance(); } public void improveWorld() { world.improve(); }

10 Minimer sideeffekt public class WorldHelper { public void improveWorld(World world) { improver.improve(world); }

11 Minimer sideeffekt public class WorldHelper { public World improveWorld(World oldWorld) { return improver.improve(world); }

12 Små, præcise metoder public World improveWorld() { Date beforeTest = new Date(Calendar.getInstance().getTimeInMillis()); assertTrue("The database should be empty to begin with.", cache.isEmpty()); // try handling output from ChecksumJob. File csFile = makeTemporaryChecksumFile1(); cache.addChecksumInformation(csFile, Replica.getReplicaFromId("ONE")); // try handling output from FilelistJob. File flFile = makeTemporaryFilelistFile(); cache.addFileListInformation(flFile, Replica.getReplicaFromId("TWO")); Date dbDate = cache.getDateOfLastMissingFilesUpdate( Replica.getReplicaFromId("TWO")); Date afterInsert = new Date(Calendar.getInstance().getTimeInMillis()); // Assert that the time of insert is between the start of this test // and now. assertTrue("The last missing file update for replica '" + Replica.getReplicaFromId("ONE") + "' should be after " + "the test was begun. Thus '" + DateFormat.getDateInstance().format(dbDate) + "' should be after '" + DateFormat.getDateInstance().format(beforeTest) + "'.", dbDate.after(beforeTest)); assertTrue("The last missing file update for replica '" + Replica.getReplicaFromId("ONE") + "' should be before " + "the current time. Thus '" + DateFormat.getDateInstance().format(dbDate) + "' should be before '" + DateFormat.getDateInstance().format(afterInsert) + "'.", dbDate.before(afterInsert)); // Check that getDateOfLastWrongFilesUpdate gives a date between // the start of this test and now. dbDate = cache.getDateOfLastWrongFilesUpdate(Replica.getReplicaFromId("ONE")); assertTrue("The last missing file update for replica '" + Replica.getReplicaFromId("ONE") + "' should be after " + "the test was begun. Thus '" + DateFormat.getDateInstance().format(dbDate) + "' should be after '" + DateFormat.getDateInstance().format(beforeTest) + "'.", dbDate.after(beforeTest)); assertTrue("The last missing file update for replica '" + Replica.getReplicaFromId("ONE") + "' should be before " + "the current time. Thus '" + DateFormat.getDateInstance().format(dbDate) + "' should be before '" + DateFormat.getDateInstance().format(afterInsert) + "'.", dbDate.before(afterInsert)); // retrieve empty file and set all files in replica 'THREE' to missing File fl2File = makeTemporaryEmptyFilelistFile(); cache.addFileListInformation(fl2File, Replica.getReplicaFromId("THREE")); flFile, // check that all files are unknown for the uninitialised replica. long files = FileUtils.countLines(csFile); System.out.println(cache.getMissingFilesInLastUpdate( Replica.getReplicaFromId("THREE"))); System.out.println(FileUtils.readListFromFile(csFile)); assertEquals("All the files for replica 'THREE' should be missing.", files, cache.getNumberOfMissingFilesInLastUpdate( Replica.getReplicaFromId("THREE"))); // check that the getMissingFilesInLastUpdate works appropriately. List misFiles = IteratorUtils.toList(cache.getMissingFilesInLastUpdate( Replica.getReplicaFromId("THREE")).iterator()); List allFilenames = new ArrayList (); for(String entry : FileUtils.readListFromFile(csFile)) { String[] e = entry.split("##"); allFilenames.add(e[0]); } assertEquals("All the files should be missing for replica 'THREE': " + misFiles + " == " + allFilenames, misFiles, allFilenames); // adding the checksum for the other replicas. cache.addChecksumInformation(csFile, Replica.getReplicaFromId("TWO")); // check that when a replica is given wrong checksums it will be // found by the update method. assertEquals("Replica 'THREE' has not been assigned checksums yet." + " Therefore not corrupt files yet!", 0, cache.getNumberOfWrongFilesInLastUpdate(Replica.getReplicaFromId("THREE"))); assertEquals("No files has been assigned to replica 'THREE' yet.", 0, cache.getNumberOfFiles(Replica.getReplicaFromId("THREE"))); File csFile2 = makeTemporaryChecksumFile2(); cache.addChecksumInformation(csFile2, Replica.getReplicaFromId("THREE")); assertEquals("All the files in Replica 'THREE' has been assigned " + "checksums, but not checksum update has been run yet. " + "Therefore no corrupt files yet!", 0, cache.getNumberOfWrongFilesInLastUpdate(Replica.getReplicaFromId("THREE"))); assertEquals("Entries for replica 'THREE' has should be assigned.", FileUtils.countLines(csFile2), cache.getNumberOfFiles(Replica.getReplicaFromId("THREE"))); cache.updateChecksumStatus(); assertEquals("After update all the entries for replica 'THREE', " + "they should all be set to 'CORRUPT'!", FileUtils.countLines(csFile2), cache.getNumberOfWrongFilesInLastUpdate(Replica.getReplicaFromId("THREE"))); assertEquals("All the entries for replica 'THREE' is all corrupt, " + "but they should still be counted.", FileUtils.countLines(csFile2), cache.getNumberOfFiles(Replica.getReplicaFromId("THREE"))); // Check that all files are wrong for replica 'THREE' List wrongFiles = IteratorUtils.toList(cache.getWrongFilesInLastUpdate(Replica.getReplicaFromId("THREE")).iterator()); assertEquals("All the files should be wrong for replica 'THREE': " + wrongFiles + " == " + allFilenames, wrongFiles, allFilenames); // check that a file can become missing, after it was ok, but still be ok! cache.addFileListInformation(

13 Små, præcise metoder public World improveWorld() { stopWars(world); waterDeserts(world); bringBackMammuts(world); …. } protected void stopWars(World world) {

14 Test design

15 Meget af det samme • Små, præcise tests • Robuste tests • Generaliser

16

17 Unit test vs. System test Unit test • Hurtige • Automatiske • Fail-pass resultat • Kodenære • Kode er testspec • Kræver udviklingsmiljø • Konsistent System test • Langsomme • Manuelle • Brugerkontrolleret • Testrapport • Del af dokumentationen som testspec • Kræver testmiljø • Explorativ testing


Download ppt "Automatisk tests og Continuous delivery Med afsæt i Bitmagasin og Netarkiv projekterne."

Similar presentations


Ads by Google