문제

아래는 Java Google App Engine을 사용하여 작성하는 웹 응용 프로그램에서 작성한 클래스입니다. TestNG와 모든 테스트 패스를 사용하여 단위 테스트를 작성했습니다. 그런 다음 Eclipse에서 Eclemma를 실행하여 코드의 테스트 범위를 확인합니다. 모든 기능에는 100% 적용 범위가 표시되지만 파일 전체에 약 27%의 적용 범위가 표시됩니다. 73%의 발견되지 않은 코드는 어디에서 나오나요?

누구든지 Eclemma의 작동 방식과 내가 왜 불일치를 얻는 지 이해하도록 도와 줄 수 있습니까?

package com.skaxo.sports.models;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType= IdentityType.APPLICATION)
public class Account {

    @PrimaryKey
    @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String userId;

    @Persistent
    private String firstName;

    @Persistent
    private String lastName;

    @Persistent
    private String email;

    @Persistent
    private boolean termsOfService;

    @Persistent
    private boolean systemEmails;

    public Account() {}

    public Account(String firstName, String lastName, String email) {
        super();
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }

    public Account(String userId) {
        super();
        this.userId = userId;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean acceptedTermsOfService() {
        return termsOfService;
    }

    public void setTermsOfService(boolean termsOfService) {
        this.termsOfService = termsOfService;
    }

    public boolean acceptedSystemEmails() {
        return systemEmails;
    }

    public void setSystemEmails(boolean systemEmails) {
        this.systemEmails = systemEmails;
    }
}

아래는 위의 클래스의 테스트 코드입니다.

package com.skaxo.sports.models;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AccountTest {

    @Test
    public void testId() {
        Account a = new Account();
        a.setId(1L);
        assertEquals((Long) 1L, a.getId(), "ID");
        a.setId(3L);
        assertNotNull(a.getId(), "The ID is set to null.");
    }

    @Test
    public void testUserId() {
        Account a = new Account();
        a.setUserId("123456ABC");
        assertEquals(a.getUserId(), "123456ABC", "User ID incorrect.");
        a = new Account("123456ABC");
        assertEquals(a.getUserId(), "123456ABC", "User ID incorrect.");
    }

    @Test
    public void testFirstName() {
        Account a = new Account("Test", "User", "test@example.com");
        assertEquals(a.getFirstName(), "Test", 
                "User first name not equal to 'Test'.");
        a.setFirstName("John");
        assertEquals(a.getFirstName(), "John", 
                "User first name not equal to 'John'.");
    }

    @Test
    public void testLastName() {
        Account a = new Account("Test", "User", "test@example.com");
        assertEquals(a.getLastName(), "User",
                "User last name not equal to 'User'.");
        a.setLastName("Doe");
        assertEquals(a.getLastName(), "Doe", 
                "User last name not equal to 'Doe'.");
    }

    @Test
    public void testEmail() {
        Account a = new Account("Test", "User", "test@example.com");
        assertEquals(a.getEmail(), "test@example.com", 
                "User email not equal to 'test@example.com'.");
        a.setEmail("john@example.com");
        assertEquals(a.getEmail(), "john@example.com", 
                "User email not equal to 'john@example.com'.");
    }

    @Test
    public void testAcceptedTermsOfService() {
        Account a = new Account();
        a.setTermsOfService(true);
        assertTrue(a.acceptedTermsOfService(),
                "Accepted Terms of Service not true.");
        a.setTermsOfService(false);
        assertFalse(a.acceptedTermsOfService(),
                "Accepted Terms of Service not false.");
    }

    @Test
    public void testAcceptedSystemEmails() {
        Account a = new Account();
        a.setSystemEmails(true);
        assertTrue(a.acceptedSystemEmails(), "System Emails is not true.");
        a.setSystemEmails(false);
        assertFalse(a.acceptedSystemEmails(), "System Emails is not false.");
    }
}
도움이 되었습니까?

해결책

이것은 추측이지만 Javadoc을 기반으로합니다. 지속 가능합니다 클래스가 JDO 인핸서가 인터페이스를 구현하기 위해 추가 코드로 짜여진 것 같습니다. 이 경우 추가 코드가 테스트에서 다루지 않을 가능성이 있습니다. 주석을 제거하고 테스트를 다시 실행하면 예상 범위가 표시됩니까?

Javadoc에서 :

참조 구현에서 JDO Enhancer는 클래스를 런타임 환경에로드하기 전에 지속 가능한 상태로 구현하도록 클래스를 수정합니다. 참조 인핸서는 또한 CODE를 추가하여 PersisTenceCapable에 의해 정의 된 메소드를 구현합니다.

디 컴파일러와 같은 것도 사용해 볼 수도 있습니다 Jad 컴파일 된 클래스를 검사하여 클래스가 컴파일 시간 (또는 프리 프로세스)에 추가 메소드가 있는지 실제로 짜여져 있는지 확인합니다. 다시 Javadoc에서 :

지속 가능한 인터페이스의 추가 방법은 .java 파일을 사전 처리하여 생성 될 수 있거나 도구에서 직접 생성 될 수 있습니다. 추가 방법을 생성하기위한 정확한 기술은 JDO에 의해 지정되지 않습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top