{"id":101,"date":"2005-10-06T08:49:49","date_gmt":"2005-10-06T12:49:49","guid":{"rendered":"http:\/\/www.dr-chuck.com\/wordpress\/?p=101"},"modified":"2011-12-17T12:18:26","modified_gmt":"2011-12-17T16:18:26","slug":"unit-testing-in-sakai","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2005\/10\/unit-testing-in-sakai\/","title":{"rendered":"UNIT Testing In Sakai"},"content":{"rendered":"<p>Well I fooled with Unit Testing in Sakai for a few hours and kind of came to a dead end.  It was pretty fun and the basic stuff worked.  My problem is that I just don&#8217;t know where to stop when creating mock versions of stuff.  I looked at unit tests in the gradebook and common and there is not much interaction witht he rest of Sakai &#8211; I want to create unit tests that can interact with the rest of Sakai.  But that means firing up components somehow (or mocking that up), firing up component manager (or mocking that up) etc etc.  The problem is that with the structure of unit tests it seems that everyone who writes a unit test is responsible for mocking up the entire rest of the system.  This is icky when dealing with a system as large as Sakai with a goal of a rich framework that *everything* depends on.  So we will need to develop a way to make unit testing easier.  Someone other than me will need to figure this out.<\/p>\n<p>\nBut here are my notes.  Thanks to Josh and Lance for their examples.<\/p>\n<p><!--more--><br \/>\nThis page is a god-send:<\/p>\n<p>\nhttp:\/\/bugs.sakaiproject.org\/confluence\/display\/ENC\/JUnit+Testing<\/p>\n<p>\nI followed this cookbook and got to the point that the I had a simple unit test working, making its local beans, finding its local beans, using its local beans and then falling on its face.<\/p>\n<p>\nI adapted Lance&#8217;s code:<\/p>\n<p>\ncommon-composite-component\/src\/test\/org\/sakaiproject\/component\/junit\/spring\/ApplicationContextBaseTest.java<\/p>\n<p>\nI removed everything Hibernate from it and got a pure spring version.  This worked once you set the variable on the maven call:<\/p>\n<p>\nmaven test -Dsakaiproject.basedir=\/Users\/csev\/dev\/sakai<\/p>\n<p>\nHere is how it looks when it runs:<\/p>\n<pre>\ntest:compile:\n[javac] Compiling 1 source file to \/Users\/csev\/dev\/sakai\/osid\/component\/target\/test-classes\nApplicationContext=org.springframework.context.support.ClassPathXmlApplicationContext: display name [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=2790855]; startup date [Wed Oct 05 23:18:11 EDT 2005]; root of context hierarchy\norg.osid.id.IdManager\nApplicationContext=org.springframework.context.support.ClassPathXmlApplicationContext: display name [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=1183826]; startup date [Wed Oct 05 23:18:11 EDT 2005]; root of context hierarchy\norg.osid.id.IdManager\ntest:test:\n[junit] Running org.sakaiproject.osid.test.IdManagerTest\nHello from my unit test...\nHere we go..\nidm=org.sakaiproject.component.osid.id.IdManager@d4461b\nException...\n[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.042 sec\nBUILD SUCCESSFUL\nTotal time: 6 seconds\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Well I fooled with Unit Testing in Sakai for a few hours and kind of came to a dead end. It was pretty fun and the basic stuff worked. My problem is that I just don&#8217;t know where to stop when creating mock versions of stuff. I looked at unit tests in the gradebook and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":1,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":2187,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/101\/revisions\/2187"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}