The Revolutionary/Evolutionary Database Projects (and Dev11)

   Posted by: Dave Zimmerman

I have been working with database projects since the 2006 CTP “Data Dude” days through its 1.0 release as Visual Studio Team Edition for Database Professionals; Its realized vision -- of organizing our database artifacts/schema into a solution; checking changes into source control (TFS) surrounded with descriptive meta data (work items) documenting the motivations for those changes; and empowering us to automate the build, deployment, and test of those changes through our staged environments – has truly been revolutionary for this aspect of software development for those who have persevered in the new discipline.  Those of you who have been using this for a while also know that tools and best practices surrounding database projects has been very evolutionary as well with each release of Visual Studio, not to mention each release of SQL Server.  The Dev 11/SQL 2012 release is no exception here.

The latest release of Visual Studio (Dev 11 at the time of this post) will upgrade your databases project (.dbproj) to a database project (.ssdt) which stands for SQL Server Developer Tools.  This is a major rework by the tools team which is now fully aligned with the various SQL server cleints with the aim of providing a unified toolset for all SQL Server Development whether you are working in SQL Server Management Studio (SSMS), Business Intelligence Design Studio (BIDS), or Visual Studio (VS).  We have been reading about this effort and/or playing with these features in Community Technology Previews (CTPs) which began integrating with Visual Studio 2010 Premium SP1 in CTP3.  The Visual Studio Dev11 Beta shipped with the release candidate 0 (RC0) of the SSDT tools.  The SSDT tools have since been released to manufacturing (RTM).  Thus, if you want to play with these tools in Dev11, a good place to start is to either download and install the Feature Pack for 2012, or just install the required VS components for the VS dev-build-deploy cycle.  Specifically for me, this consists of 64-bit DACFramework.msi, SqlSystemClrTypes.msi, SQLDOM.msi, and SQLLS.msi.  Those of you installing on 32-bit build machines, would want to install the 32-bit versions of those downloads.

Dev11 Bug Alert: If you are getting the following error on your Dev11 64-bit build machines when you go to build your .ssdt projects:

clip_image002[6]C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets (381): The "SqlModelResolutionTask" task could not be loaded from the assembly C:\Program Files\Microsoft SQL Server\110\DAC\Bin\Microsoft.Data.Tools.Schema.Tasks.Sql.11.dll. Could not load file or assembly 'file:///C:\Program Files\Microsoft SQL Server\110\DAC\Bin\Microsoft.Data.Tools.Schema.Tasks.Sql.11.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Workaround: This is due to a bug in the Dev11 build targets.  The workaround is to copy your DAC files from the (x86) Program files directory to a 64-bit location, for example:

C:\Program Files (x86)\Microsoft SQL Server\110\DAC\Bin\

gets copied to

C:\Program Files\Microsoft SQL Server\110\DAC\Bin\

Not So Fast On that Uninstall

Great strides have been made with SSDT projects.  Just to name a few, developers working offline in declarative mode using LocalDB or online interacting with a shared database both get a greatly improved Transact-SQL Debugging and testing experience; one database project is used for all versions of SQL Server and the organization of database artifacts is much friendlier/more intuitive than the previous .dbproj.  On the other hand, while there are many great new features, not all the old features of database projects you may be taking advantage of have made it into the SSDT code rewrite (See SQL Server Data Tools CTP4 vs. VS2010 Database Projects ) and conversions aren’t no-brainers for all database projects (See Top VSDB->SSDT Project Conversion Issues)  [As an aside, our upgrade team was not impressed with the upgrade logic used by the database project conversion wizard.  If you don’t mind not losing your seamless history of artifact changes in your .dbproj, I recommend just pointing at a database and recreating your solution as an SSDT rather than the really odd arrangement of new and old scripts you acquire over time while working with a converted .dbproj file.  However, for those who do want to keep this history, manually upgraded, e.g moving artifacts to the appropriate folders and deleting others is a tedious option.] 

SNAGHTML155916c

Example of “upgraded” database project which preserves the .dbproj artifact organization.  Unfortunately when new artifacts get added, the solution places them in the new .ssdt folder organization.  (Now we have 2 “Production folders” – and a solution which is in neither the .dbproj nor .ssdt canonical form,  Worse yet, you may start getting compiler errors after synching table changes because with .ssdt projects index scripts are stored in the table definition itself for readability (Nice!), But it does not clean up the .dbproj’s pattern of storing index scripts as separate files.   

So in your exuberance over the new features, don’t be too hasty clicking Uninstall on your dev machine and build machine VS2010 installations, especially if you want to continue using features, like for example, the data generation/compare tools.  But keep a stiff upper lip as well, Microsoft is already narrowing the gap with out-of-band power tools that integrate with the 2012 tools (See  SSDT PowerTools which at the time of this writing has re-integrated the Schema Explorer with .ssdt projects) 

Java QA - Tools for Unit Testing

   Posted by: Jim White

Most Java developers are familiar with, either by practice or at least by reputation, JUnit.  JUnit is an open source unit testing framework for Java often used in test-driven development environments.  However, there is another option that is less know but equally, and some might say more, powerful than JUnit and that is TestNG.  Both JUnit and TestNG are both considered Java implementations of Kent Beck and Eric Gamma's Smalltalk SUnit (commonly referred to as xUnit frameworks).

Both are so close in implementation, that Spring's Test Context Framework allows either to be used (to some degree interchangeably) with the same effectiveness.

Getting your Java Unit Testing Framework

JUnit is available at http://www.junit.org/ and the current release is 4.10.  TestNG is available at http://testng.org.  .As of this writing, the latest release is 6.3.1.

Comparison

At the core, you'll find JUnit and TestNG very similar in API and functionality.  Both TestNG and JUnit are largely annotation-based frameworks.  Both offer tests that can be executed through Eclipse (via plugin in one case) and other IDEs like IntelliJ by IDEA (http://www.jetbrains.com/idea/features/junit_testng.html).

There are a few good online comparisons of JUnit and TestNG (links provided below) and so I won't provide a complete comparison here.

Description
Link
May 2011 comparison listing core differences with comments from readers. http://technologyandleadership.com/junit-vs-testng-core-differences/
Aug 2006 IBM developerWorks article http://www.ibm.com/developerworks/java/library/j-cq08296/
May 2009 comparison http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/
Nov 2008 Similarities/Differences comparison http://docs.codehaus.org/display/XPR/Migration+to+JUnit4+or+TestNG
Aug 2011 Javalobby comparison http://java.dzone.com/articles/testng-or-junit

There are plenty of examples of small syntactical differences between the two frameworks, but these are usually more stylistic than substantive.  Take for example the annotation to ignore a test.  In JUnit, a special @Ignore annotation defines a test method that should be skipped.  TestNG accomplishes the same objective with a parameter on @Test annotation (the enabled parameter).

   1: // TestNG skipped test
   2: @Test(enabled=false)
   3: public void testSaveContactList() {
   4:     for (Contact contact : list.getContacts()) {
   5:         service.addContact(contact);
   6:         System.out.println(contact + " was added to the Contact DB");
   7:     }
   8: }
   1: // JUnit skipped test
   2: @Test
   3: @Ignore
   4: public void testSaveContactList() {
   5:     for (Contact contact : list.getContacts()) {
   6:         service.addContact(contact);
   7:         System.out.println(contact + " was added to the Contact DB");
   8:     }
   9: }

Another example of a small syntactical difference can be found in the before and after test initialization method annotations.  JUnit uses @Before and @After.  TestNG uses @BeforeMethod and @AfterMethod.

   1: // TestNG test initialization
   2: @BeforeMethod
   3: public void doSetup(){
   4:     System.out.println("initializing");
   5: }
   1: // JUnit test initalization
   2: @Before
   3: public void doSetup(){
   4:     System.out.println("initializing");
   5: }

Where the two differ is that TestNG offers a bit more functionality around initialization and tear down procedures regarding test suites/groups.  @BeforeSuite, @AfterSuite, @BeforeGroups, and @AfterGroups are TestNG annotations for conducting setup/tear down work before or after a suite or group of tests.  JUnit and TestNG offer capability to do initialization and clean up before and after each test or before or after all tests in a class, but these unique TestNG annotations allow for initialization and clean up before and after suites and groups of tests.  JUnit does not offer similar capability.

Organizationally, the diagram below indicates the order in which these initialization/tear down methods are invoked with regard to TestNG tests.

image

TestNG also allows for dependencies between tests.  Using the dependsOnMethods parameter of the @Test annotated methods, you can create methods that execute only upon the successful execution of other test methods.  In the example below, the testDeleteContact method (deleting a Contact with ID = 1) only executes if the testGetContact method is able to retrieve a Contact with ID = 1.

   1: @Test
   2: public void testGetContact(){
   3:     System.out.print("Getting contact 1");
   4:     service.getContact(1L);
   5: }
   6:  
   7:  
   8: @Test(dependsOnMethods = { "testGetContact" }) 
   9: public void testDeleteContact(){
  10:     System.out.println("Deleting contact 1");
  11:     service.removeContact(1L);
  12: }

JUnit also has a construct foreign to TestNG.  The JUnit Runner allows you to tell JUnit how a test should run and then executes the tests.  The Runner notifies a RunNotifier of events.  This allows the Runner to notify JUnit of the progress running tests.  Runners and RunNotifiers allow for a lot of customization in how JUnit executes tests and displays results.

There are also capabilities that both frameworks offer that are implemented in such different ways that some may really prefer the syntax and organization of the function better in one framework over the other.  TestNG groups versus JUnit categories comes to mind.  Both allow test methods to be organized into more discrete partitions of tests.  This allows you to include or exclude certain tests and/or devise more flexible test plan organizations.  I find TestNG's groups a little easier to work with as JUnit's categories require setting up special marker interfaces, but both groups and categories get the job done.

   1: // TestNG groups.  In this case two groups are defined:  foos and bars
   2: @Test(groups = { "foos" })
   3: public void testMethodFoo() {
   4:  
   5: }
   6:  
   7: @Test(groups = { "bars" })
   8: public void testMethodBar() {
   9:  
  10: }
  11:  
  12: @Test(groups = { "foos", "bars" })
  13: public void testMethodFarBar() {
  14: }

image

   1: // JUnit categories.  In this case two categories are defined:  foos and bars
   2: public interface Foos { }
   3: public interface Bars { }
   4:  
   5: public class A {
   6:     @Category(Foos.class)
   7:     @Test public void testMethodFoo() {}
   8: }
   9:  
  10: @Category(Bards.class})
  11: public class B {
  12:     @Test public void testMethodBar() {}
  13: }
  14:  
  15: @RunWith(Categories.class)
  16: @IncludeCategory(Bars.class)
  17: @ExcludeCategory(Foos.class)
  18: @SuiteClasses({ A.class, B.class })
  19: public class MyTestSuite {}

Note, categories were added to JUnit 4.8.  Therefore it is a pretty recent addition to JUnit and not available in most JUnit environments.

Another example of somewhat similar functionality but rather different implementations comes in parameter passing between tests (something JUnit did not allow by design in order to keep individual tests isolated and separate from on another until relatively recent).

   1: // TestNG - one of many ways to pass parameters to a test method
   2: @DataProvider(name = "firstName")
   3: public Object[][] createData() {
   4:     return new Object[][] { { "Jim" }, { "Joe" }, };
   5: }
   6:  
   7: @Test(dataProvider = "firstName") 
   8: public void testPassParameter(String firstName) {
   9:     System.out.println("Invoked test with String " + firstName);
  10: }
   1: // JUnit - one way to use parameters in methods
   2: @RunWith(Parameterized.class)
   3: public class MyTest {
   4:  
   5:     private String firstName;
   6:  
   7:     public MyTest(String firstName){
   8:         this.firstName = firstName;
   9:     }
  10:     
  11:     @Parameters
  12:     public static Collection<Object[]> generateData() {
  13:         return Arrays.asList(new Object[][] { { "Jim" }, { "Joe" } });
  14:     }
  15:  
  16:     @Test
  17:     public void testPassParameter() {
  18:         System.out.println("Invoked test with String " + firstName);
  19:     }
  20: }

IDE Support

By and large, you will find the major IDE's support either JUnit or TestNG.  The difference is whether the IDE comes with built-in support or does it require a plug-in to support the unit test framework.  JUnit support is already built into Eclipse.  If you create a JUnit test or test suite, you can immediately run the class as a JUnit Test.  Results of the test are displayed in a built in a JUnit Eclipse view.

image

TestNG requires a plugin be installed to execute TestNG tests.  Instructions for installing the plugin can be found on the Intertech site here:  TestNG Plugin Document.  Once the plug-in is installed, a TestNG view displays the test results similar to the JUnit view.

image

IntelliJ supports both JUnit and TestNG (see here).  NetBeans supports JUnit (see here), but also requires a plugin like Eclipse for TestNG (see here).

Performance (Unscientific)

I conducted a little test to see how well both JUnit and TestNG performed.  In particular, I had a ContactDAO class.  I performed 1000 each of the following test operations:  get all contact objects, get a contact object by id, update a contact object, and add a new contact object.  So each unit test performed 4000 DAO method calls.  After each unit test, I emptied the database and reset the environment back to its original state.  The results are shown in the table below.

times in milliseconds TestNG JUnit
Test Run #1 6803 6076
Test Run #2 7317 6108
Test Run #3 9020 6045
Test Run #4 6850 5872
Test Run #5 8004 5952
Average Run Time 7599 6011
Standard Deviation 851 87

Based on my test, you can see that JUnit did marginally better, but perhaps more importantly, JUnit performed more consistently than did TestNG.  Again, this study should not be considered scientific and you should perform your own analysis to be sure the performance of the unit test framework you choose meets your needs.

Spring Integration

Spring has acknowledge the importance of both frameworks in that the Spring Test Context framework allows either to be used.   Today, the TestContext Framework works with JUnit (version 4 or better), and TestNG (version 5 or better) unit testing tools out of the box.  JUnit 3.8 is supported but considered deprecated.  The reasons for using the TestContext Framework (versus just using a unit test framework directly) are many.

  • Using the Spring TestContext Framework allows unit tests and unit test code to be decoupled from the actual testing framework.  This allows you to switch between TestNG and JUnit as your unit test framework of choice with relative ease.
  • Spring provides transaction management that better supports unit testing.
  • Transaction management support allows changes to the database to be appropriately rolled back after conducting tests.
  • Spring dependency injection can be used to construct more/better integrated component tests - facilitating tests at the unit and integration level.

Except for the unit test framework specific annotations that can be used, the only real difference in using JUnit versus TestNG with Spring is that when using JUnit4, the TestContext class can be annotated with the @RunWith annotation that specifies the unit test runner used by the framework for executing tests.  When using TestNG, the TestContext class must extend one of Spring's TestContext support classes (like AbstractTestNGSpringContextTests).

Wrap Up

Beyond JUnit and TestNG, you'll find plenty of other open-source Java Testing Tools at java-source.net/open-source/testing-tools.  Before thinking Java quality assurance and test driven development is all about JUnit, check out TestNG and do a little research into some of the additional tooling.

While you are at it, check out Intertech's JUnit class.  Find more information at Express JUnit.  While it is only a small part of our Spring class, you'll also find JUnit and TestNG integration is covered in our Spring class (see Complete Spring 3 Framework).

QA / QC : A World of Testing Terms

   Posted by: Andrew Troelsen

I remember many (many) years ago where it was very common for programmers to make use of ?printf debugging? as a testing strategy. If you have never heard of this term, it is just like it sounds: litter your source code with various printf() statements to print out the values of data points, in a crude attempt to see how the software is behaving (if you were really fancy, you might have wrapped these statements in #ifdef scopes to only print out the data in a debug build!).

Nowadays development shops can employ full Quality Assurance (QA) / Quality Control (QC) teams to test software during every phase of the software lifecycle. While many programmers are acquainted with unit testing (as it is typically the programmers themselves who do such testing), this is just the test of the testing iceberg.

Let?s defines some (but certainly not all) common terms of the testing universe.

  • Unit Testing: This level of testing is concerned with testing the interface to a give module (input to the module and output from the module). The term ?module? could be regarded as a single method, however it is also common to regard a ?module? as a given class.  This type of testing is divided into two broad categories.  Static unit testing typically involves code walkthroughs, code reviews and/or formal inspections. Dynamic unit testing happens during program execution and is what is most often thought of for most developers.
  • Control Flow Testing: This is a form of ?white box? testing, where the tester is concerned with testing branching, looping, assignment and ?jump? statements within a module. For example, say a method has a set of if/else statements (or maybe a switch) which is dependent on class variables. This type of testing would attempt to hit all branches of the underlying predicates.  You might also recall the role of McCabe?s cyclomatic complexity? That value can be determined (in part) by building a control flow graph, which captures the set of independent paths in the module under test.
  • Data Flow Testing: This flavor of testing is closely related to CF testing (see previous). However, rather than looking exclusively at branching logic, data flow testing is more concerned the deltas on data in the module under test. How is the data changing?  Is it being computed correctly? Does is correctly evaluate predicates for branching?
  • Integration Testing: The is the deal breaker for many systems?.once we have tested units to our best ability, how does the software behave once they are combined into a cohesive unit? Do the interfaces of the individual classes match up? To messages flow correctly through the system?  The overall goal of integration testing is to build a reasonably stable system which can be readied for the next flavor of testing.
  • System Testing: Once we have a stale system, system testing allows us to see how our product performs in the wild. More specifically, system testing can involve a full install of the software on a reprehensive machine. Functional and non-functional aspects of the software are tested at this point (but system testing is not technically acceptance testing!). This level of testing allows us to see if the software matches up with our requirements and specifications, if the software runs well under the target environment (OS, memory, etc.)
  • Acceptance Testing: Here, we are getting ready for the big hand off. Does our system satisfy the customer requirements? This level of testing might involve user usage tests, pushing the software into the business cycle or both. By the time we get here, we are looking for the final sign off (which could be bound by contract or very informal).

Now, for you professional testers out there, you might note this list of terms is incomplete (domain and functional testing give me the willies). However, these terms are fairly common in the software development community, and it is always good to have some simple reminders on what happens to our software beyond pushing bits and bites.

Here, I simply offered some definitions for common terms. Any of these testing categories could easily be blown up into a full book to cover all the details. Perhaps in future blog posts I?ll examine some of these testing techniques as seen though the eyes of a .NET developer using Microsoft development tools?.

Happy coding.

Find Us
Contact Us 651-288-7000 1-800-866-9884
Home | Training | Curriculum | Course Finder | Schedule | Enroll | Twin Cities Java User Group | Consulting | Foundation | Jobs | About Us | Our Story | Press Room | Instructors | President | Map & Directions | Sitemap

Java Training | JSF / Struts / Spring / Hibernate Training | Java Power Tools Training | .NET 4.0 & Visual Studio 2010 Training | Microsoft Web Development Training | Prism / MVVM / MEF Training | .NET 3.5 and Visual Studio 2008 Training | .NET 2.0 and Visual Studio 2003 Training | Cloud Computing Training | Ajax / Web Services / XML Training | Groovy and Grails Training | SQL Server 2012 Training | SQL Server 2008 Training | SQL Server 2005 Training | Mobile Development Training | SharePoint 2010 Training | SharePoint 2007 Training | Agile, Process, Analysis & Design Training | Arch/Design Patterns Training | Microsoft Official Curriculum Training | Web Development Training | Ruby Training | Rational Application Developer (RAD) Training | WebSphere Application Server Training | WebSphere Portal Training | WebLogic Training | Boot Camp Training | Project Management Training | C / C++ Training | Metro / WinRT / Windows 8 Development Training | Retired

Intertech delivers training on-site and virtually serving cities including Phoenix, AZ | San Francisco, CA | Los Angeles, CA | San Diego, CA | San Jose, CA | Washington, DC | Chicago, IL | Orlando, FL | Boston, MA | Duluth, MN | Minneapolis St. Paul, MN | Rochester, MN | Raleigh-Durham, NC | New York, NY | Philadelphia, PA | Austin, TX | Dallas, TX | Houston, TX | Seattle, WA.